0

我有一个用于在 php 中重新调整图像大小的代码......它在本地机器上运行良好并正确分割......图像在所有 4 种尺寸中都是可见的......但是,当我在服务器中使用它时......图像大小是重新调整大小......原始图像可见......调整大小的图像不可见......带有黑色......解决方案是什么......这是我使用的代码......

主文件

<?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>

拇指.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);
}
?>

中.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);
}
?>

大的.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);
}
?>
4

1 回答 1

0

您可能需要检查文件/目录的权限,以确保它们可以被您的 PHP 脚本读写。

于 2013-01-09T04:32:33.227 回答