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

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.

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.