Jump to content

Upload unable to move


samtwilliams
Go to solution Solved by mac_gyver,

Recommended Posts

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

Edited by samtwilliams
Link to comment
Share on other sites

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
Share on other sites

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.