theUnforgiven's avatar

File uploads

I'm having a little bit of trouble with a script of mine.

I'm wanting to upload a file but it's not moving the file to the correct place, instead it's creating a tmp then a random string then the file. obviously this is not correct.

Here's the upload script:

           $file = Input::file('file');
            $destinationPath = public_path(). '/upload/' .Input::get('folder') . $file;

            $filename = $file->getClientOriginalName();
            $upload_success = Input::file('file')->move($destinationPath, $filename);

Input::get('folder') returns the number of the selected folder that corresponds to a folder number in the upload directory.

So the question is what am I doing wrong why is it no just moving the file to (in this instance) upload/4/mydoc.pdf

Instead it does upload/4/tmp/pjDRfe/mydoc.pdf

0 likes
3 replies
Cocoon's avatar
Cocoon
Best Answer
Level 7

Hmm, not sure, but shouldn't the destination path just be like so:

$destinationPath = public_path(). '/upload/' .Input::get('folder');
// leave off . $file?
1 like
coderx's avatar

I am new to laravel too but I think i can help you. Check this line of the code: $destinationPath = public_path(). '/upload/' .Input::get('folder') . $file;

If you want to upload the image to public/upload folder, all you need to do is remove this line of code which is Input::get('folder') and also check the .$file that you added.

You can do this if you want: $file = Input::get('file'); $file = $file->getClientOriginalName(); $destinationPath = public_path(). '/upload/' . $file;

Please or to participate in this conversation.