i have a problem, could anyone help me?

basically my code is this:

if (move_uploaded_file($_FILES['file']['tmp_name'],
       'users/' .$_SESSION['ID']. '/' .$res['id'].'.'.$type)){
       ?> <h align="center">Upload Successful</h> <?php

but when i use it in the web i get the following error:

Warning: move_uploaded_file(users/8/3/) [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: failed to open stream: No such file or directory in C:\xampp\htdocs\mike\upload.php on line 17

Warning: move_uploaded_file() [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: Unable to move 'C:\xampp\tmp\php9634.tmp' to 'users/8/3.cpp' in C:\xampp\htdocs\mike\upload.php on line 17

I think the problem is in the permissions, searching the web i have only gotten misguided and had to reinstall apache.

btw im using Win 7 , Xampp

5 Years
Discussion Span
Last Post by veedeoo


Running xampp in windows, the directories are CHMOD'ed at 777 or writtable by default, so I can assure you there is not permission problem there.

Try, go to your localhost, the click on phpinfo(), find the value of upload_max_filesize and post_max_size. These values should be at least change to 60M or better yet make it as hight as 300M depending on what types of file your server will be accepting for uploads.

By looking at your script above, you are attempting to rename the uploaded file. Am I right? If so, we need to find the file extension of the uploaded file first, and then move the uploaded file to your target directory.

Something like this. I have no time to test this , but this is pretty much you will need.

 ## this is your uploaded file in the tmp directory e.g. C:\xampp\tmp\php9634.tmp
 $tempfile = $_FILES['file']['tmp_name'];

 ## the file name of uploaded file as shown on your desktop e.g. somefile.jpg
  $filename =($_FILES['file']['name']);

 ## we get the extension of the uploaded file
 $ext = substr( $filename, strrpos($filename, '.') + 1);

 ## we define new filename without extension
 $newFilename = $res['id'];

 ## we check if directory exist
 $upload_dir = "users/".$_SESSION['ID'];

 if (!file_exists( $upload_dir)){
 ## create directory
 mkdir( $upload_dir, 0777, true);
 ## we set permission to 0777 or 777
 ## this may not work in windows, and should be commented, but should work in linux servers.
 chmod($upload_dir, 0777);


 ## we are done checking if everything are ok, we can now move the uploaded file from the tmp directory
      if (move_uploaded_file($_FILES['file']['tmp_name'],
'.$upload_dir.'/' .$newFilename.'.'.$ext)){
?> <h align="center">Upload Successful</h> <?php

Edited by veedeoo: more info added

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.