Jump to content

[SOLVED] move uploaded file help


ngreenwood6

Recommended Posts

I am having a problem trying to upload a file and then display it on another page. I am getting this error:

 

Warning: move_uploaded_file(c:/wamp/www/upload/upload/) [function.move-uploaded-file]: failed to open stream: Permission denied in C:\wamp\www\upload\check_image.php on line 27

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\wamp\tmp\php609.tmp' to 'c:/wamp/www/upload/upload/' in C:\wamp\www\upload\check_image.php on line 27

 

 

 

I am trying to upload the upload the file to "c:\wamp\www\upload\upload\". I am using wamp server obviously so if you wer to use the url it would be "http://localhost/upload/upload/". My upload file looks like this:

 

upload.php

<?php

//database variables
$host = "localhost";
$user = "root";
$pass = "";
$db = "pictures";
$table = "data";


//connect to the database
$connect = mysql_connect($host, $user, $pass);

//select database
mysql_select_db($db);

//get variables from form
$image_caption = $_POST['image_caption'];
$image_username = $_POST['image_username'];
$image_tempname = $_POST['image_filename']['name'];
$today = date("Y-m-d");

//upload image and make sure path is correct
$imagedir = "c:/wamp/www/upload/upload/";
$imagename = $imagedir . $image_tempname;

if (move_uploaded_file($_FILES['image_filename']['tmp_name'], $imagename))
{

//get info about the image being uploaded
list($width, $height, $type, $attr) = getimagesize($imagename);

switch ($type)
{
case 1:
$ext = ".gif";
break;

case 2:
$ext = ".jpg";
break;

case 3:
$ext = ".png";
break;

default:
echo "Sorry, but the file you uploaded was not a GIF, JPG, or " . "PNG file.";
echo "Please hit your browser's 'back' button and try again.";
}

//insert info into image table
$insert = "INSERT INTO insert (image_caption, image_username, image_date) VALUES ('$image_caption','$image_username','$today')";

$insertresults = mysql_query($insert)
or die(mysql_error());

$lastpicid = mysql_insert_id();

$newfilename = $imagedir . $lastpicid . $ext;

rename($imagename, $newfilename);

}
?>

<html>
<head>
<title>Here is your pic!</title>
</head>
<body>
<h1>So how does it feel to be famous?</h1>
<br />
<br />
<p>Here is the picture that you just uploaded to our servers:</p>
<img src="upload/<?php echo $lastpicid . $ext; ?>" align="left" />
<strong><?php echo $image_name; ?></strong>
<br />
This image is a <?php echo $ext; ?> image.<br />
It is <?php echo $width ?> pixels wide and <?php echo $height; ?> pixels high.<br />
It was uploaded on <?php echo $today; ?>.
</body>
</html>

 

Any help is greatly appreciated. If you have any questions feel free to ask.

Link to comment
https://forums.phpfreaks.com/topic/120403-solved-move-uploaded-file-help/
Share on other sites

for funsies try adding these lines above the move_uploaded_file line

 

<?php
chmod($_FILES['image_filename']['tmp_name'], 0777);
chmod($imagedir, 0777);
?>

 

I should note that chmod isn't supposed to work on windows, but I've heard reports of it working under some circumstances.

just in case anyone cares I figured out the issue i changed this code:

 

$image_tempname = $_POST['image_filename']['name'];

 

to this code:

 

$image_tempname = $_FILES['image_filename']['name'];

 

So I accidently put post where the files command should have been. Thought this might be helpful for some of you out there. I would have thought that someone would have caught this though. oh well.

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.