CAO
CAO

Reputation: 131

Getting error in uploading file in php

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.

Upvotes: 0

Views: 2358

Answers (2)

Rubin Porwal
Rubin Porwal

Reputation: 3845

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

Upvotes: 0

Starx
Starx

Reputation: 78971

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.

Upvotes: 1

Related Questions