vidyashankara Posted July 28, 2006 Share Posted July 28, 2006 index.php[code]echo "<p><img src=/images/part2index.jpg><form enctype=multipart/form-data method=post action=upload.php><input type=file name=file /> <input type=image src=/images/uploadindex.jpg value=Upload></form>";[/code]upload.php[code]ini_set("display_errors",1);$time=time();// Where the file is going to be placedchdir("uploaded_pdb");mkdir($time,0777);chdir($time);$target_path = "uploaded_pdb/$time/";/* Add the original filename to our target path. Result is "uploads/filename.extension" */$filename = basename($_FILES['file']['name']);$target_path = $target_path . $filename;// This is how we will get the temporary file...$tmpname = $_FILES['file']['tmp_name'];$move = move_uploaded_file($tmpname, $target_path);if ($move) { echo "The file $filename has been uploaded";} else { echo "There was an error uploading the file, $filename, please try again!";}print "<pre>";echo 'Here is some more debugging info:<br>';print_r($_FILES);print "</pre>";[/code]Output of array file[code]Array( [file] => Array ( [name] => 1.txt [type] => text/plain [tmp_name] => /tmp/phpyxLK1B [error] => 0 [size] => 666 ))[/code]the error i get is [code]Warning: move_uploaded_file(uploaded_pdb/1154116683/1.txt): failed to open stream: No such file or directory in /var/www/html/pdbreader/upload.php on line 20Warning: move_uploaded_file(): Unable to move '/tmp/phpyxLK1B' to 'uploaded_pdb/1154116683/1.txt' in /var/www/html/pdbreader/upload.php on line 20There was an error uploading the file, 1.txt, please try again![/code]whats wrong??? the code looks perfect to me... Quote Link to comment https://forums.phpfreaks.com/topic/15925-upload-script-extremely-irritating/ Share on other sites More sharing options...
lead2gold Posted July 28, 2006 Share Posted July 28, 2006 [code]// Where the file is going to be placedchdir("uploaded_pdb");mkdir($time,0777);chdir($time);$target_path = "uploaded_pdb/$time/";[/code]if you changed to the directory successfully then the new target_path is this:[code]$target_path = "$time/";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15925-upload-script-extremely-irritating/#findComment-65404 Share on other sites More sharing options...
vidyashankara Posted July 28, 2006 Author Share Posted July 28, 2006 i changed it to [code]$target_path = "";[/code]because i changed to $time before itself. Works great now. Thanks :) Quote Link to comment https://forums.phpfreaks.com/topic/15925-upload-script-extremely-irritating/#findComment-65407 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.