Уплоад форма

XTYLING

Registered
upload_image.htm
Код:
<html>
<head>
<title>Upload your pic to our site!</title>
</head>
<body>

<form name="form1" method="post" action="check_image.php" enctype="multipart/form-data">

<table border="0" cellpadding="5">
	<tr>
		<td>Image Title or Caption<br />
        	<em>Example: You talkin' to me?</em></td>
        <td><input name="image_caption" type="text" id="item_caption" size="55" maxlength="255" /></td>
    </tr>
    <tr>
    	<td>Your Username</td>
        <td><input name="image_username" type="text" id="image_username" size="15" maxlength="255" /></td>
    </tr>
    <tr>
    	<td>Upload Image:</td>
    	<td><input name="image_filename" type="file" id="image_filename"></td>
    </tr>
</table><br />
<em>Acceptable image formats include: GIF, JPG/JPEG, and PNG.</em>
<p align="center"><input type="submit" name="submit" value="Submit" /> 
<input type="reset" name="submit2" value="Clear Form" />
</p>
</form>
</body>
</html>

check_image.php
Код:
<?php

include("config.php");

//make variables available
$image_caption = $_POST['image_caption'];
$image_username = $_POST['image_username'];
$image_tempname =  $_FILES['image_filename']['name'];
$today = date("Y-m-d");

//upload image and check for image type
//make sure to change your path to match your images directory
$imageDir = "C:/AppServ/www/images/";
$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";
		default:
			echo "Sorry, but the file you uploaded was not a GIF , JPG, or PNG file.<br>";
			echo "Please hit your browser's 'back' button and try again.";
	}
	
	//insert into image table
	
	$insert = mysql_query("INSERT INTO images
						  (image_caption, image_username, image_date)
						  VALUES
						  ('$image_caption','$image_username','$today')") 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 you just uploaded to our servers:</p>
<img src="images/<?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>

а ми излиза тази грешка: Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\WINDOWS\Temp\php13.tmp' to '' in C:\AppServ\www\check_image.php on line 16
 
$imageDir = "C:\AppServ\www\images\";

направи си го така. или добави @ пред move_file
 
Код:
    <?php
    


include("config.php");

//make variables available
$image_caption = $_POST['image_caption'];
$image_username = $_POST['image_username'];
$image_tempname =  $_FILES['image_filename']['name'];
$today = date("Y-m-d");

//upload image and check for image type
//make sure to change your path to match your images directory
$imageDir = "C:/AppServ/www/images/";
$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";
      default:
         echo "Sorry, but the file you uploaded was not a GIF , JPG, or PNG file.<br>";
         echo "Please hit your browser's 'back' button and try again.";
   }
   
   //insert into image table
   
   $insert = mysql_query("INSERT INTO images
                    (image_caption, image_username, image_date)
                    VALUES
                    ('$image_caption','$image_username','$today')") or die(mysql_error());

   $lastpicid = mysql_insert_id();
   
   $newfilename = $ImageDir . $lastpicid . $ext;
   
   rename($ImageName, $newfilename);
}

?>
 
ab0d2aa1aafff34e.GIF
 
оправих го но заради този ред:

$ImageDir = "С:\AppServ\www\images\"; ми излиза от \"; като коментар
 

Back
Горе