Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problems with move_uploaded_file

Status
Not open for further replies.

rudenborg

Programmer
May 18, 2004
19
US
I'm having problems with the following script:
Code:
	if (isset($_POST['submit_picture']))
		{
			//
			// check the caption variable
			if (empty($_POST['caption']))
			{
				$c = '';
			}
			else
			{
				$c = $this->escape_data($_POST['caption']);
			}
			
			if (empty($_FILES['upload']['name']))
			{
				$u = FALSE;
				$this->message('<p>You forgot to choose a file.</p>');
			}
			else
			{
				$u = $_FILES['upload'];
			}
				
			$this->connect_to_mysql('2');
			$name = "{$_FILES['upload']['name']}";
			$query = "INSERT INTO pictures (picture_id, file_name, caption, orientation, year, upload_date) VALUES ('NULL', '$name', '$c', 'V', '{$_POST['year']}', 'NULL')";
			$result = mysql_query($query);
			
			if ($result && $u)
			{
				$extension = explode ('.', $_FILES['upload']['name']);
				$uid = mysql_insert_id();
				$filename = $uid.'.'.$extension[1];
				if (move_uploaded_file($_FILES['upload']['tmp_name'], "../$filename"))
				{
					$this->message('Your picture has been added to the pictures page.</p>');
				}
				else
				{
					$this->message('<p>The file could not be moved.</p>');
					
					$query = "DELETE FROM pictures WHERE picture_id = $uid";
					$result = mysql_query($query);
				}
			}
			else
			{
				$this->message('<p>Please try again.</p>');
			}
				
		}
I keep getting the following errors:

Warning: move_uploaded_file(../25.doc): failed to open stream: Permission denied in /Users/joanna/Sites/rcvf/admin/control_pictures.php on line 71

Warning: move_uploaded_file(): Unable to move '/var/tmp/phpM6J3wA' to '../25.doc' in /Users/joanna/Sites/rcvf/admin/control_pictures.php on line 71


I'm running this script on my personal computer (a MAC running OS X.2). Is there any reason why I shouldn't have permission to copy the file to a folder inside my Sites folder? Or does this not realy have anything to do with permissions?

I'll be gratfull for any help you can give -- this has been driving me crazy!

Jonathan
 
Your web server runs as a user, and any filesystem operations (such as move_uploaded_file()) will use the permissions of that user.

What permissions does your web server's login have to the folder?


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Boy I feel stupid. That did it.

As an addition question though, is there a way to set permissions on a file (with PHP) when your moving it with move_uploaded_file() function? I set the permissions correct on the folder but when each file gets moved the permisions on that file are set to "no access".

Thanks again for your help!

Jonathan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top