0

I am trying to create a upload form through which the user can enter certain details(including a file upload) and then it will be inserted into a database, the row is entered successfully but I get this error. i.e Warning: move_uploaded_file(upload/computer/SIGN 001.jpg): failed to open stream: No such file or directory in C:\wamp\www\stockm.php on line 28 & Warning: move_uploaded_file(): Unable to move 'C:\wamp\tmp\php2CEE.tmp' to 'upload/computer/SIGN 001.jpg' in C:\wamp\www\stockm.php on line 28

this is the code which has the entire scripting for the upload file portion.

$name= $_FILES['file']['name'];
  $tmp_name = $_FILES['file']['tmp_name']; 
  $type = $_FILES['file']['type']; 
  $size = $_FILES['file']['size'];
  $pathAndName = "upload/computer/".$name;
  $moveResult = move_uploaded_file($tmp_name, $pathAndName);

I have created a folder in C:/wamp/upload named computer where I want the image to be sent, in the database I get this location but in upload/computer there is no file, the folder is empty.

1
  • You are in www and are trying to upload to /wamp/www/upload which probably does not exist. Use an absolute path for the target path as well Commented Aug 4, 2013 at 14:43

2 Answers 2

1

Your path $pathAndName = "upload/computer/".$name; is a relative path, thus it will search from the current directory of the executing script.

For example, if you are running from wamp\www\test\upload.php it will search for wamp\www\test\upload\computer\ path.

You can assign the path from the root directory as "/upload/computer/".$name;, this will search for wamp\www\upload\computer path.

Further more, you have to check if the folder exist in the path and it has permission to access it or read it.

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

Comments

0

As a solution to your problem please try executing following code snippet for uploading file

$name= $_FILES['file']['name'];
$tmp_name = $_FILES['file']['tmp_name']; 
$type = $_FILES['file']['type']; 
$size = $_FILES['file']['size'];
$pathAndName = $_SERVER['DOCUMENT_ROOT']."upload/computer/".$name;
$moveResult = move_uploaded_file($tmp_name, $pathAndName);

In above code snippet I have specified absolute path for destination path where the file needs to be uploaded

1 Comment

thanks a lot, but if I assign this value in $pathandname then its still searching for directory in www, but the folder upload is in the folder wamp, how to set directory for that.

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.