Jump to content

Recommended Posts

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...

 

 

 

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

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) :confused:

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.