SachinAgarwal's avatar

[L5] Uploading Image

I am aware of the process of the uploads. But I'm little confused here.

  1. There is no way to get the temp name of file from laravel?
  2. Or is that Laravel rename the temp name of file to client's original name?
  3. If I do move() will it be removed from temp folder?
  4. If I do unlink(Request::file('image')->getClientOriginalName()) without calling move() will it remove the uploaded file from temp folder?

Basically I am trying to take the upload image from html form and resize it and save it. For this I'm using Intervention/image package. And this package have a save() method already. So after saving I want to remove the uploaded image from the temp folder.

0 likes
4 replies
usman's avatar
usman
Best Answer
Level 27

@SachinAgarwal 1 - you can retreive the file's temp name using the getRealPath() method on the file:

$file = $request->file('myfile');
var_dump($file->getRealPath()); // will dump something like /tmp/phpZNWzmr

2- Or is that Laravel rename the temp name of file to client's original name?

No.

3- If I do move() will it be removed from temp folder?

At the end of script execution php will remove the files from tmp directory. So, unless you are renaming the file inside the tmp directory you don't need to worry about that. Just move it to your intended location.

Usman.

1 like
SachinAgarwal's avatar

@pmall thanks I have watched those videos earlier but Some how I missed the manipulation part in laravel-image-manipulation video. :P

@usman Thanks a lot for clearing my confusion :)

kunaldodiya's avatar

I want to create image upload function while user create any classified post, but the problem is i want to allow user post without login, so temporary image is stored in tmp folder and when user click post, i will move the tmp images to his gallery like username/gallery/

now, its easy uptill now but when user want to edit same post, i want to show the uploaded images and he also can delete existing or add more, this is little bit awkward as now user is already logged in I dont need Tmp folder but i will directly upload images in his gallery.. please, help in creating this logic :)

Please or to participate in this conversation.