August 4, 2013

Getting error in uploading file in php

CAO’s Question:

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:wampwwwstockm.php on line 28
&
Warning: move_uploaded_file(): Unable to move ‘C:wamptmpphp2CEE.tmp’ to ‘upload/computer/SIGN 001.jpg’ in C:wampwwwstockm.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.

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 wampwwwtestupload.php it will search for wampwwwtestuploadcomputer path.

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

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

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!