samtwilliams Posted June 21, 2014 Share Posted June 21, 2014 Hi All, I have this issue when upload a file using an uploader i made. For the life of me I cant figure out why it won't write the file. Error: [Sat Jun 21 20:45:40 2014] [error] [client xxxxxxx] AH01215: PHP Warning: move_uploaded_file() [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: Unable to move '/tmp/phpUsCyXG' to '/home/sites/xxxxxx.co.uk/public_html/yourphotos/uploads/' in /home/sites/xxxxxxx.co.uk/public_html/yourphotos/index.php on line 31 My PHP <?php //if they DID upload a file... $message = ''; if($_FILES['photo']['name']) { $valid_file = true; //if no errors... if(!$_FILES['photo']['error']) { //now is the time to modify the future file name and validate the file $new_file_name = strtolower($_FILES['photo']['tmp_name']); //rename file if($_FILES['photo']['size'] > (26214400)) //can't be larger than 25MB { $valid_file = false; $message = 'Oops! Your file\'s size is to large.'; echo $_FILES['photo']['size']; } if($_FILES['photo']['size'] < (1572864)) //can't be smaller than 1.5MB { $valid_file = false; $message = 'Oops! Your file\'s size is to small.'; echo $_FILES['photo']['size']; } //if the file has passed the test if($valid_file) { //move it to where we want it to be move_uploaded_file($_FILES['photo']['tmp_name'], '/home/sites/xxxxxxxx.co.uk/public_html/yourphotos/uploads/'); $message = 'Congratulations! Your file was accepted.'; } } //if there is an error... else { //set that to be the returned message $message = 'Ooops! Your upload triggered the following error: '.$_FILES['photo']['error']; } } ?> <html> <body> <form action="index.php" method="post" enctype="multipart/form-data"> Your Photo: <input type="file" name="photo" size="25" /> <input type="submit" name="submit" value="Submit" /> <?PHP echo $message; ?> </form> </body> </html> I have set the uploads file to have write permissions as well. Sam Link to comment https://forums.phpfreaks.com/topic/289231-upload-unable-to-move/ Share on other sites More sharing options...
mac_gyver Posted June 21, 2014 Share Posted June 21, 2014 the destination parameter of the move_uploaded_file() function must include the file name. yours only has the path. Link to comment https://forums.phpfreaks.com/topic/289231-upload-unable-to-move/#findComment-1482999 Share on other sites More sharing options...
samtwilliams Posted June 21, 2014 Author Share Posted June 21, 2014 thanks, solved by if($valid_file) { //move it to where we want it to be $target_path = "/home/sites/xxxxxx.co.uk/public_html/yourphotos/uploads/"; $target_path = $target_path . basename( $_FILES['photo']['name']); move_uploaded_file($_FILES['photo']['tmp_name'], $target_path); $message = 'Congratulations! Your file was accepted.'; } Link to comment https://forums.phpfreaks.com/topic/289231-upload-unable-to-move/#findComment-1483001 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.