Jump to content

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.

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.