环境是:apache+php+mysql
把一张图片上传到htdocs目录下的images文件夹中,要写入数据库的信息能正常写入,但图片却无法上传.
提示
Warning: imagejpeg() expects parameter 1 to be resource, string given in D:\Program Files\WEB\Apache\htdocs\GD\check_image.php on line 73这个是check_image.php的代码:<?php
include 'database.php' ;
$dir = 'D:/Program Files/WEB/Apache/htdocs/images' ;
if($_FILES['uploadfile']['error']!=UPLOAD_ERR_OK){
switch ($_FILES['uploadfile']['error']) {
case UPLOAD_ERR_INI_SIZE:
die('The uploaded file exceeds the upload_max_filesize directive in php.ini') ;
break;
case UPLOAD_ERR_FORM_SIZE:
die('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form') ;
break;
case UPLOAD_ERR_PARTIAL:
die('The uploaded file was only partially uploaded.') ;
break;
case UPLOAD_ERR_NO_FILE:
die('No file was uploaded.') ;
break;
case UPLOAD_ERR_NO_TMP_DIR:
die('The server is missing a temporary folder.') ;
break;
case UPLOAD_ERR_CANT_WRITE:
die('The server failed to write the loaded file to disk.') ;
break;
case UPLOAD_ERR_EXTENSION:
die('File up;pad stopped by extension.') ;
break;
}
}
$image_caption = $_POST['caption'] ;
$image_username = $_POST['username'] ;
$image_date = @date('Y-m-d') ;
list($width,$height,$type,$attr) = getimagesize($_FILES['uploadfile']['tmp_name']) ;
switch ($type) {
case IMAGETYPE_GIF:
$image = imagecreatefromgif($_FILES['uploadfile']['tmp_name']) or
die('The file you uploaded was not a wupported filetype.');
$ext='.gif' ;
break;
case IMAGETYPE_JPEG:
$image = imagecreatefromjpeg($_FILES['uploadfile']['tmp_name']) or
die('The file you uploaded was not a wupported filetype.');
$ext='.jpeg' ;
break;
case IMAGETYPE_PNG:
$image = imagecreatefrompng($_FILES['uploadfile']['tmp_name']) or
die('The file you uploaded was not a wupported filetype.');
$ext='.png' ;
break;
default:
die('The file you uploaded was not a supported filetype.') ;
}
$query = 'INSERT INTO images(image_caption,image_username,image_date)
VALUES
("' . $image_caption . '",
 "' . $image_username . '",
 "' . $image_date . '")' ;
$result = mysql_query($query,$db) or die(mysql_error($db)) ;

$last_id = mysql_insert_id() ;

$imagename = $last_id . $ext ;

$query = 'UPDATE images SET image_filename = "' . $imagename . '"
WHERE
image_id = ' .$last_id ;
$result = mysql_query($query,$db) or die(mysql_error($db)) ; switch ($type){
case IMAGETYPE_GIF:
$image = imagegif($dir . '/' . $imagename) ;
break ;
case IMAGETYPE_JPEG:
$image = imagejpeg($dir . '/' . $imagename,100) ;
break ;
case IMAGETYPE_PNG:
$image = imagepng($dir . '/' . $imagename) ;
break ;
imagedestroy($image) ;
}
?>
<html>
<head>
<title>Here is your pic!</title>
</head>
<body>
<h1>So how does it feel to be famous?</h1>
<p>Here is the picture you just uploadd to our servers:</p>
<img src="\images\<?php echo $imagename?>" style="float:left;">

<!--<img src="\images\apple.jpg" style="float:left;">

--><table>
<tr><td>Image Saved as: </td><td><?php echo $imagename; ?> </td></tr>
<tr><td>Image Saved as: </td><td><?php echo $ext; ?> </td></tr>
<tr><td>Height: </td><td><?php echo $height; ?> </td></tr>
<tr><td>Width: </td><td><?php echo $width; ?> </td></tr>
<tr><td>Upload Date: </td><td><?php echo $image_date; ?> </td></tr>
</table>
</body>
</html>