2

When I try to upload image from the form , Laravel is creating directory out of image name. Here is my basic code:

$file = Input::file("image");
$file = $file->move(public_path(). "/img/".$file->getClientOriginalName());

//file name is IPC_diagram.png

When die and dump I got this:

'/var/www/php/frbit/l4blog/public/img/IPC_diagram.png/phpvEb9zk'

Now name of image is name of new folder and image is renamed to some random php string, and placed in that folder. What is the problem. Maybe something related to Linux specific handling of files. Also I was looking into symfony code for this, and symfony is trying to crete new folder every time file is moved but I don't understand how it is related to my code.

Thanks for help.

2
  • 5
    My mistake - there are two arguments in the move function. First is path to directory and second (optional) is file name. So I should split the with comma. Commented Jan 24, 2014 at 9:47
  • 1
    you should add this as the answer. Thanks for posting. Commented Sep 16, 2014 at 6:22

1 Answer 1

3

Do not use dot. Use comma, like this:

$name = time() . $file->getClientOriginalName();
$file->move('uploads/posts/',$name);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.