0

Im currently working with Jcrop to let users crop an image, after they crop they can upload the image, I want to use php to crop the image and move the file to the correct directory.

This is the tutorial im following: Tutorial

In my i have this input element :

<input type="file" name="upload-image" id="upload-image"/>

then when the image crop region is selected with Jcrop the user will upload the form. this is the bit of PHP which is not working:

 // new unique filename
 $sTempFileName = 'cache/' . md5(time().rand());

 // move uploaded file into cache folder
 move_uploaded_file($_FILES['upload-image']['tmp_name'], "upload/" . $sTempFileName);

Then when i upload the form i get these 2 errors.

Warning: move_uploaded_file(../upload/cache/6b769249a48996fd69d527b2412b684e): failed to open stream: No such file or directory

and

Warning: move_uploaded_file(): Unable to move 'C:\wamp1\tmp\phpB1A0.tmp' to '../upload/cache/6b769249a48996fd69d527b2412b684e'

I checked a lot of stackoverflow pages already but the all use a folder to upload the image to, but in this tutorial it says it needs to upload the file into the cache folder. That makes me think i don't need to specify a folder to upload to.

3
  • I am using this: enctype="multipart/form-data" on my form Commented May 19, 2016 at 12:52
  • file extention name is missing Commented May 19, 2016 at 13:02
  • Possible duplicate of Failed to open stream : No such file or directory Commented May 19, 2016 at 19:31

1 Answer 1

1

Make sure the target directory (../upload/cache/) exists and is writable by the web server. If you're not certain where the upload/cache directory should be, you can find out by temporarily adding this line right before the call to move_uploaded_file:

echo realpath($sTempFileName);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot, Turns out the $sTempFileName is /cache/randomgeneratedname. I just realised.

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.