I am having this errors:
imagecopyresampled() expects parameter 2 to be resource, string given in C:\xampp\htdocs file_put_contents(): supplied resource is not a valid stream resource in C:\xampp\htdocs
<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 80000))
{
if($_FILES["file"]["error"]>0)
{
echo "Error:".$_FILES["file"]["error"]."</br>";
}
else
{
echo "Upload: ".$_FILES["file"]["name"]."</br>";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Stored in: " . $_FILES["file"]["tmp_name"];
$tmp=$_FILES["file"]["tmp_name"];
if (file_exists("images/" . $_FILES["fil开发者_如何学Goe"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
$image = file_get_contents($tmp);
$new_image = imagecreatetruecolor(200, 200);
imagecopyresampled($new_image, $image, 0, 0, 0, 0, 200, 200, imagesx($image), imagesy($image));
file_put_contents($image, $new_image);
move_uploaded_file($_FILES["file"]["tmp_name"],
"images/" . $_FILES["file"]["name"]);
echo "Stored in: " . "images/" . $_FILES["file"]["name"];
}
}
}
else
{
echo"Invalid file";
}
?>
Change this line:
$image = file_get_contents($tmp);
To:
$image = imagecreatefromstring(file_get_contents($tmp));
imagecopyresampled
expects the second parameter to be a GD image resource, not a string which is the result of file_get_contents
. Use imagecreatefromstring
to convert that string representation of an image to an image resource.
精彩评论