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/File/UploadedFile.html
$photo = Request::file('photo');
$photo->move('/path/to/move', 'filename.jpg');
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.
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.
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());
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.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community