Support the ongoing development of Laravel.io →
Requests Input Laravel.io
Last updated 7 months ago.
0

You file does get uploaded to the server. you need to move it somewhere and save that record to the db. Here are a list of things you can do with the UploadedFile instance http://api.symfony.com/2.0/Symfony/Component/HttpFoundation/Fi...

0
$photo = Request::file('photo');
$photo->move('/path/to/move', 'filename.jpg');
0

astroanu said:

$photo = Request::file('photo');
$photo->move('/path/to/move', 'filename.jpg');

This is the problem. When i try to move the file , its throws errors.

I check file by using Request::hasFile('photo') and if its true, then i try to move file to local disk (with all access) but it throws error.

0

what exception do you get ??

0

astroanu said:

what exception do you get ?? ahhh, i used try & catch for exception and it was that little tiny winny noobie mistake. the folder permission error. Anyway. your answer assured me that i was on correct path. here is my code

Route::post('up',function(){

    $title = Input::get('title');
    $path = public_path() . '/uploads/';

    try {
        if(Request::hasFile('photo')){
            $photo = Request::file('photo');
            $photo->move($path,$title);
            $reply = 'File Uploaded';
        }else {
            $reply = 'File Not Found';
        }
    }catch (Exception $e){
        $reply = $e;
    }

    return $reply;

});

but a new problem arises. file is not being save as jpg or png.

Last updated 6 years ago.
0

The second parameter is the name of the file you are saving to. You need to explicitly give the file extension. As i said go through the link i gave you, it shows all the methods available in the UploadedFile instance. You can get the file extension using getExtension() method.

$photo->move($path, $title . '.' . $photo->getExtension());
0

astroanu said:

The second parameter is the name of the file you are saving to. You need to explicitly give the file extension. As i said go through the link i gave you, it shows all the methods available in the UploadedFile instance. You can get the file extension using getExtension() method.

$photo->move($path, $title . '.' . $photo->getExtension());

That did the trick. I wasn't using getExtension(), as i was pulling up the extension directly in $title form android.

Thanks for your time and effort.

Last updated 6 years ago.
0

good to know it helped!

0

Sign in to participate in this thread!

LoadForge

Your banner here too?

dukejib dukejib Joined 14 May 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2022 Laravel.io - All rights reserved.