charlie_d Posted March 3, 2008 Share Posted March 3, 2008 Hi, I am new to PHP and am having major problems with a basic upload script as follows: Using php 5.2.5 and IIS on my local machine. Am trying to run a very basic upload script print_r($_FILES); gives me all the correct details of the uploaded file and [error] => 0 but when I check the tmp upload folder as specified in php.ini and as returned by print_r($_FILES); , there is no .tmp file. Also move_uploaded_file always returns false. What am I doing wrong Quote Link to comment Share on other sites More sharing options...
Rohan Shenoy Posted March 3, 2008 Share Posted March 3, 2008 Please post your upload script. Quote Link to comment Share on other sites More sharing options...
discomatt Posted March 3, 2008 Share Posted March 3, 2008 Lost a bit of data with the downfall... as I said before PHP doesn't have permission to create/write the file in the directory your are specifying. Try using an absolute path, and make sure the folder exists. Quote Link to comment Share on other sites More sharing options...
charlie_d Posted March 3, 2008 Author Share Posted March 3, 2008 Thanks discomatt but; Images folder exists and I have also tried using different folders created sepecially to test this, and I have used both relative and absolute paths and with slashes going both ways. Still getting nowhere Due to loss of posts - here is problem again in full: I am using php 5.2.5 and IIS 5.1 on MS Windows Pro with SP2 installed I am attempting a simple file upoad with first page: <form enctype="multipart/form-data" action="test_uploadck.php" method="POST"> <!-- MAX_FILE_SIZE must precede the file input field --> <input type="hidden" name="MAX_FILE_SIZE" value="75000" /> <!-- Name of input element determines name in $_FILES array --> Send this file: <input name="userfile" type="file" /> <input type="submit" value="Send File" /> </form> and test_uploadck.php: <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); print "<pre>"; $target_path = 'Images/'; $target_path = $target_path . basename( $_FILES['userfile']['name']); if(move_uploaded_file($_FILES['userfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['userfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } echo 'Here is some more debugging info:'; print_r($_FILES); print "</pre>"; ?> I get the following errors: Warning: move_uploaded_file(Images/AL19307A.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in C:\Inetpub\wwwroot\estateagent1\test_uploadck.php on line 18 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\PHP\tmp\php43.tmp' to 'Images/AL19307A.jpg' in C:\Inetpub\wwwroot\estateagent1\test_uploadck.php on line 18 I have checked the standard pitfalls as follows: a) the file being uploaded was not too big (only 22K) and did not exceed either MAX_FILE_SIZE (750000) in the script or post_max_size and upload_max_filesize (both 8M) in php.ini. b) the folder I was moving the uploaded file to exists and has all permissions enabled in IIS c) There were no normal input fields in the upload form Where am I going wrong? Quote Link to comment Share on other sites More sharing options...
kkeim Posted March 3, 2008 Share Posted March 3, 2008 Try using the fopen function to read the temp file. By doing this we would know that; is the file getting saved in temp directory? if yes, you can fread the file till filesize extent and fwrite to your destination. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.