jameswagoner's avatar

File does not exist after successfull Input::file()->move

Very basic file upload is not moving my file to final destination despite no exceptions being raised. I am using Homestead for some context.

$file = Input::file('file');
$name = strtolower(str_replace(' ', '-', $file->getClientOriginalName()));
$dest = app_path('public').'/albums';

$file->move($dest, $name);

I checked the albums folder for the file and not there. Confused, I did dd($file->move($dest, $name)) and the File object was returned. Checked the folder permissions, they are good (running Homestead so ownership isn't an issue).

Not sure what the issue is here. With no exception being raised, I don't have any leads.

0 likes
4 replies
jekinney's avatar
Level 47

App_path is wrong.

To test DD $dest. But you want public_path(). Also check laravel docs under helpers then paths.

jameswagoner's avatar

From php artisan tinker:

[1] > app_path('public');
// '/home/vagrant/Sites/my-ste/app/public'

And yes, I know about public_path(). app_path() is used extensively in my application for other directories other than public so I chose to remain consistent.

jasonfrye's avatar

Just a quick checklist to ensure the file is being handled...

  1. You have 'files' => true if you're using the Form::open class?
  2. The file is within the limits of your php.ini max_upload limit?
  3. Albums exists as a folder in public?
  4. Nothing in your logs -- laravel or server?
jameswagoner's avatar

Discovered my error. Knew there had to be a user error somewhere.

@jekinney - Apologies, you are correct regarding public_path(). While app_path() was working for other methods in my application, they were not publicly accessible files. I even missed the seeing app in that output I posted. Found my files sitting in /app/public/....

@jasonfrye - Those are all things I checked and have setup while provisioning my Homestead instance. Thanks for the leads.

2 likes

Please or to participate in this conversation.