freelance84 Posted June 21, 2011 Share Posted June 21, 2011 Could someone please help me out, i'm stuck... Trying to get a file from the tmp folder to overwrite an existing file in the public _html. Here is php: ini_set('display_errors',1); error_reporting(E_ALL); //printing the files and post to check what is being recieved print_r($_FILES); print_r($_POST); //moving the file from the temp folder on the server to the actual final resting place.. ie the new destination //the file name in the temp folder on the server: $theTempFile = $_FILES['fileToUpload']['tmp_name']; if(move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $dirFile)) { echo "move_uploaded_file(".$_FILES['fileToUpload']['tmp_name'].", $dirFile)"; } else{ echo 'error'; } $time = time(); //now update the mySql ftp_management table $query_update = mysql_query("UPDATE ftp_management SET beingEdited = 'no', finishTime = '$time', finishNotes = '$theReasons' WHERE theFile = '$dirFile_mysql' "); if(!$query_update) { echo mysql_error(); exit(); } exit(); The source of the html output is: Array ( [fileToUpload] => Array ( [name] => 000.html [type] => text/html [tmp_name] => /tmp/phpRHiI7f [error] => 0 [size] => 642 ) ) Array ( [uploadFileName] => 000.html [uploadFileDestination] => ../public_html/ [uploadFormReason] => asef ) move_uploaded_file(/tmp/phpRHiI7f, ../public_html/000.html) The file doesn't actually move to the public_html folder however, it does update the entry in the mySql table. As you can see the file to transfer does get uploaded as printing the $_FILES displays its existance. The move_uploaded_file is doing something as the if is printing (the last line in the html source) I've checked the permissions on the public_html, they are set to 755 as is the tmp folder. I was wondering, the printed version of the move_uploaded_file function shows 2 dots before the public_html but not the /tmp. I have tested putting the two dots before the '/tmp and removing the two dots before the public_html: Both print the error message programmed for when the move_uploaded_file fails... Really know what is stopping it overwriting the existing file... Quote Link to comment https://forums.phpfreaks.com/topic/240010-move_uploaded_file-not-moving-a-file-to-the-public_html/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 21, 2011 Share Posted June 21, 2011 What makes you think that the file isn't being moved/overwriting an existing file? Quote Link to comment https://forums.phpfreaks.com/topic/240010-move_uploaded_file-not-moving-a-file-to-the-public_html/#findComment-1232902 Share on other sites More sharing options...
fugix Posted June 21, 2011 Share Posted June 21, 2011 What fo you have your $dirFile set to Quote Link to comment https://forums.phpfreaks.com/topic/240010-move_uploaded_file-not-moving-a-file-to-the-public_html/#findComment-1232904 Share on other sites More sharing options...
freelance84 Posted June 21, 2011 Author Share Posted June 21, 2011 AHHHH.... i dont know. Now it mysteriously started working again. I really don't know what it is. What makes you think that the file isn't being moved/overwriting an existing file? I used the script to upload a modified page late this aft and html page in question did not change. I did a few futher tests and all i got was an updated mysql table but no new file on the server. Perhaps it something to with my hosting company. This issue: http://www.phpfreaks.com/forums/index.php?topic=336267.msg1584008#msg1584008 still exists, and i can still interrogate files on the host outside of 'my area'. Maybe they are fiddling with things. What fo you have your $dirFile set to It's is set further up in the 'uploader' script, but you can see what it is from the html ouput i printed in the OP. Ok I don't know. If I find a resolve as to why it sometimes fails I will post the results. I'll have to give the people at my host another call Quote Link to comment https://forums.phpfreaks.com/topic/240010-move_uploaded_file-not-moving-a-file-to-the-public_html/#findComment-1232911 Share on other sites More sharing options...
PFMaBiSmAd Posted June 21, 2011 Share Posted June 21, 2011 html page in question did not change How do you know that it did not change? Quote Link to comment https://forums.phpfreaks.com/topic/240010-move_uploaded_file-not-moving-a-file-to-the-public_html/#findComment-1232917 Share on other sites More sharing options...
freelance84 Posted June 21, 2011 Author Share Posted June 21, 2011 html page in question did not change How do you know that it did not change? Because i corrected some wording. After uploading the said file the wording hadn't changed. I then repeated the upload script with a test subject file name 000.html changing the wording, but the same thing happened. What really is a little strange is that since the OP time and now i have made no changes to the script but now it works again (it happens that as soon as i read your first response i tested again to double check and found it working again) Quote Link to comment https://forums.phpfreaks.com/topic/240010-move_uploaded_file-not-moving-a-file-to-the-public_html/#findComment-1232927 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.