i have a code for re-sizing image in php... it works well in local machine and splitting correctly...images are visible in all 4 sizes... but,when am using this in server...image size is re-sized...original image is visible...resized image is not visible...comes with black color...what is the solution for it...here is the code i used...
main.php
<?php
if(isset($_POST['submit']))
{
$uploaddir = 'uploads/';
$file = basename($_FILES['uploadedfile']['name']);
$uploadfile = $uploaddir . $file;
move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $uploadfile);
include ("thumb.php");
$target=$_FILES['uploadedfile']['name'];
$new='uploads/'."thumb_".$target;
$type=$_FILES['uploadedfile']['type'];
$w=90;
$h=90;
resize($target,$new,$w,$h,$type);
include ("medium.php");
$new1='uploads/'."middle_".$target;
$type1=$_FILES['uploadedfile']['type'];
$w1=400;
$h1=400;
resizee($target,$new1,$w1,$h1,$type1);
include ("big.php");
$new2='uploads/'."big_".$target;
$type2=$_FILES['uploadedfile']['type'];
$w2=900;
$h2=900;
resizeee($target,$new2,$w2,$h2,$type2);
echo "thumb_".$target."<br>";
echo "middle_".$target."<br>";
echo "big_".$target."<br>";
}
?>
<html>
<body>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="uploadedfile">
<input type="submit" name="submit">
</form>
</body>
</html>
thumb.php
<?php
function resize($target,$new,$w,$h,$type)
{
echo $target;
list($wo,$ho)=getimagesize('uploads/'.$target);
if($type=="image/jpeg")
{
$m=imagecreatefromjpeg('uploads/'.$target);
}
elseif($type=="image/gif")
{
$m=imagecreatefromgif('uploads/'.$target);
}
elseif($type=="image/png")
{
$m=imagecreatefrompng('uploads/'.$target);
}
$change=imagecreatetruecolor($w,$h);
imagecopyresampled($change,$m,0,0,0,0,$w,$h,$wo,$ho);
imagejpeg($change,$new,90);
}
?>
medium.php
<?php
function resizee($target,$new1,$w1,$h1,$type)
{
list($wo1,$ho1)=getimagesize('uploads/'.$target);
if($type=="image/jpeg")
{
$m1=imagecreatefromjpeg('uploads/'.$target);
}
elseif($type=="image/gif")
{
$m1=imagecreatefromgif('uploads/'.$target);
}
elseif($type=="image/png")
{
$m1=imagecreatefrompng('uploads/'.$target);
}
$change1=imagecreatetruecolor($w1,$h1);
imagecopyresampled($change1,$m1,0,0,0,0,$w1,$h1,$wo1,$ho1);
imagejpeg($change1,$new1,500);
}
?>
big.php
<?php
function resizeee($target,$new2,$w2,$h2,$type)
{
list($wo2,$ho2)=getimagesize('uploads/'.$target);
if($type=="image/jpeg")
{
$m2=imagecreatefromjpeg('uploads/'.$target);
}
elseif($type=="image/gif")
{
$m2=imagecreatefromgif('uploads/'.$target);
}
elseif($type=="image/png")
{
$m2=imagecreatefrompng('uploads/'.$target);
}
$change2=imagecreatetruecolor($w2,$h2);
imagecopyresampled($change2,$m2,0,0,0,0,$w2,$h2,$wo2,$ho2);
imagejpeg($change2,$new2,900);
}
?>
您可能需要检查文件/目录上的权限,以确保您的PHP脚本可读取和写入它们。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.