Hi all I am trying to upload a file using PHP. I can successfully create a folder, but when I try upload the file it gives me the following error when using the move_uploaded_file function:
Warning: move_uploaded_file(c:/program files/apache group/apache/htdocs/zerodocs/40/) [function.move-uploaded-file]: failed to create stream: Permission denied in c:\program files\apache group\apache\htdocs\zero\opdocument.php on line 80 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'c:\temp\php7C.tmp' to 'c:/program files/apache group/apache/htdocs/zerodocs/40/' in c:\program files\apache group\apache\htdocs\zero\opdocument.php on line 80 Error: Unable to move file to designated directory. I have checked that filesize, directory, filename etc... to make sure it should work. I have come to the conclusion that it is the permissions of the directory created. I am using a windows box. I have read the also when using mkdir() the mode is ignored for windows machines, so is it a permission problem or am I missing something? below is a copy of my upload function: // root path $path = $_SERVER['DOCUMENT_ROOT']; // upload directory. path will originate from root. $dirname = '/zerodocs/' . $_SESSION['o_id'] . "/"; // permission settings for newly created folders $chmod = 0755; // create file vars to make things easier to read. $filename = $_FILES['myfile']['name']; $filesize = $_FILES['myfile']['size']; $filetype = $_FILES['myfile']['type']; $file_tmp = $_FILES['myfile']['tmp_name']; $file_err = $_FILES['myfile']['error']; $file_ext = strrchr($filename, '.'); // check if user actually put something in the file input field. if (($file_err == 0) && ($filesize != 0)) { // Check extension. if (!$file_ext) { unlink($file_tmp); die('File must have an extension.'); } // extra check to prevent file attacks. if (is_uploaded_file($file_tmp)) { /* * check if the directory exists * if it doesnt exist, make the directory */ $dir = $path . $dirname; if (!is_dir($dir)) { $dirtemp = explode('/', $dirname); foreach ($dirtemp as $sub_dir) { $path .= '/' . $sub_dir; if (!is_dir($path)) { if (!mkdir($path, $chmod)) { unlink($file_tmp); die('<strong>Error:</strong> Directory does not exist and was unable to be created.'); } } } } /* * copy the file from the temporary upload directory * to its final detination. */ echo("Dir: " . $dir); echo("<br> filename: " . $filename); if (move_uploaded_file($file_tmp, $dir)) { // get date time stamp $today=getdate(); $dt=$today['year']."-". $today['mon']."-".$today['mday']." ".$today['hours'].":".$today['minutes'].":".$today['seconds']; //add file and directory info to the database for the operation $connect->addFileTodb($_SESSION['o_id'], $filename, $dir, $dt); } else { // error moving file. check file permissions. unlink($file_tmp); echo '<strong>Error:</strong> Unable to move file to designated directory.'; } } else { // file seems suspicious... delete file and error out. unlink($file_tmp); echo '<strong>Error:</strong> File does not appear to be a valid upload. Could be a file attack.'; } } else { // Kill temp file, if any, and display error. if ($file_tmp != '') { unlink($file_tmp); } switch ($file_err) { case '0': echo 'That is not a valid file. 0 byte length.'; break; case '1': echo 'This file, at ' . $filesize . ' bytes, exceeds the maximum allowed file size as set in <em>php.ini</em>. '. 'Please contact your system admin.'; break; case '2': echo 'This file exceeds the maximum file size specified in your HTML form.'; break; case '3': echo 'File was only partially uploaded. This could be the result of your connection '. 'being dropped in the middle of the upload.'; case '4': echo 'You did not upload anything... Please go back and select a file to upload.'; break; } } } Thanks in advance Angelo -------------------------------------------------------------------- Disclaimer This e-mail transmission contains confidential information, which is the property of the sender. The information in this e-mail or attachments thereto is intended for the attention and use only of the addressee. Should you have received this e-mail in error, please delete and destroy it and any attachments thereto immediately. Under no circumstances will the Cape Technikon or the sender of this e-mail be liable to any party for any direct, indirect, special or other consequential damages for any use of this e-mail. For the detailed e-mail disclaimer please refer to http://www.ctech.ac.za/polic or call +27 (0)21 460 3911 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php