Jump to content

move_uploaded_file warning


tecmeister

Recommended Posts

Hi every one,

 

I have been creating a form to upload data and images for a news page.  But it seems to be having a problem moving the image to the folder that I have select.

 

 

Warning: move_uploaded_file(me.png) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/cxgsyste/public_html/test/add.php on line 30

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpJSOKwU' to 'me.png' in /home/cxgsyste/public_html/test/add.php on line 30

 

Here is the script.


<form action="<?php $_SERVER['PHP_SELF']. '?insert_tech_news=' ?>" enctype="multipart/form-data" method="post">
                	Title:<br />
                	<input type="text" name="title" style=" width: 99%" />
                    <br /><br />
                    
                    Info:<br />
                    <textarea name="info" rows="10" cols="80"></textarea>
                    <br /><br />
                    <input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
                    Upload Image:<br />
                    <input type="file" name="userfile" />
                    <br /><br />
                    <input type="submit" value="Add Tech News" name="tech" />
                    </form>

<?php
if(isset($_POST['tech'])){
	$title = $_POST['title'];
	$info = $_POST['info'];
	$date = date("L jS F Y h:i:s");

	$upload_dir = "new_tech/";
	$fileName = $_FILES['userfile']['name'];
	$tmpName = $_FILES['userfile']['tmp_name'];
	$fileSize = $_FILES['userfile']['size'];
	$fileType = $_FILES['userfile']['type'];
	$filePath = $uploadDir . $fileName;

	$result = move_uploaded_file($tmpName, $filePath);
	if(!result){
		echo "Upload Error";
		exit();
	}

	if(!get_magic_quotes_gpc()){
		$fileName = addslashes($fileName);
		$filePath = addslashes($filePath);
	}

	$query = "INSERT INTO tech(title, info, date, name, size, type, path)
			VALUES ('$title','$info','$date','$fileName','$fileSize','$fileType','$filePath')";
	$result = mysql_query($query)or die(mysql_error());
}
?>

 

Thanks for your help,

 

tecmeister.

Link to comment
https://forums.phpfreaks.com/topic/157956-move_uploaded_file-warning/
Share on other sites

Sorry I have just learnt that off a tutorial.  It worked on the WAMP server.  But When I put if on to a web server it came up with that warning.

 

Please will you be able to point me in the right direct of what I sould be doing.

 

Thanks for your help Neil,

 

tecmeister.

As your error clearly states:

failed to open stream: Permission denied

 

Either you have not set the path to the folder correctly in the script, the folder has the wrong ownership i.e it should not be owned by root, and or the permissions on the folder are incorrect.

Archived

This topic is now archived and is closed to further replies.

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