2

HTML

<form enctype="multipart/form-data" id="SubmitForm" method="post" action="serv.php">
  <input type="file" name="IMG" size="chars">
  <input type="Submit" value="SAVE">
</form>

PHP

$target = 'upload/';
$target = $target . basename($_FILES['IMG']['name']);
if (move_uploaded_file($_FILES['IMG']['tmp_name'], $target)) {           //line 66
    echo 'File uploaded successfully';
} else {
    echo 'Sorry, there was a problem uploading file'
}

PROBLEMS

Warning: move_uploaded_file(upload/image.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\xampp\htdocs\test\include\pages\editor\ged.php on line 66

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\xampp\tmp\php5E.tmp' to 'upload/image.jpg' in C:\xampp\htdocs\test\include\pages\editor\ged.php on line 66

Sorry, there was a problem uploading file

I had added a file existence check and it passed, proving the file exists. I believe the problem lies somewhere within the PHP code I specified here.

Also, I've used a similar code on an earlier script and it worked. I expected this to be no different. I am beginning to think the problem is related to how the temporary file is handled? I do not know, which is why I'm here.

Apologies if this thread is a clone but all or any previous threads bearing a similar name provided solutions that did not prove to be useful for me (in my scenario).

Any help or advice is appreciated greatly. Where am I going wrong? And how can this be corrected?

5
  • does upload/ exist? Do you mean ./upload/ Commented Jun 15, 2012 at 7:28
  • Does C:\xampp\htdocs\test\include\pages\editor\upload exist? Commented Jun 15, 2012 at 7:29
  • What in $_FILES["IMG"]["error"]? var_dump($_FILES["IMG"]["error"]); Commented Jun 15, 2012 at 7:30
  • var_dump($_FILES["IMG"]["error"]); is int(0) Commented Jun 15, 2012 at 7:32
  • try using getcwd() to create the absolute path just in case, try not to hard code it, since it makes it hard to deploy the system on other machines. Commented Jun 15, 2012 at 7:45

3 Answers 3

2

Apparently, we have two PHP files involved, serv.php and ged.php, and it sounds like they are located in different directories. If you use relative paths in such layout, the path is interpreted by default as relative to the main script location, i.e. serv.php. So you want this:

C:\xampp\htdocs\test\include\pages\editor\upload

... but it's possible that PHP is looking for e.g. this:

C:\xampp\htdocs\test\upload

The simplest fix is to use absolute paths.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. The upload folder required that I put it in the same directory as serv.php.
1

The $target upload refers to C:\xampp\htdocs\test\include\pages\editor\upload\. It sounds like this folder doesn't exist or doesn't have write permissions.

7 Comments

Well I'm pretty sure It exists. And I see no reason why is should be write protected.
Try changing "upload/" to "upload\". Windows might be having issues with the incorrect Directory Separator.
Alternatively, also try changing to an absolute path. The upload file might be relastive to serv.php if serv.php includes ged.php
"\" character is an Escape Sequence. Adding it messes up the string.
the 'upload' folder in in the 'editor' directory. The same which houses the ged.php. It is relative to ged.php.
|
1

Sorry for my english ;o) Error in include file. But the directory "upload" must be in the same directory with file serv.php if you include ged.php in serv.php.

htdocs/.../ -
   upload - dir
   serv.php - file
   ... other files and directories

1 Comment

Thanks. The upload folder required that I put it in the same directory as serv.php.

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.