0

这是我的代码,我没有看到我的问题......不,感谢您的帮助!

现在它上传更改质量并复制到我的目录,但像素在大图像或小图像上保持不变

不确定我的问题出在哪里,因为我检查了几十个示例,看起来我的代码卡住了,任何帮助都会很棒!

    //Upload Directory Build
    $uploaddir = './images/projects_data/' . $_POST['table'] . '/' . $id;
    $uploadfile = $uploaddir . '/' . $db_picture;

if (isset($_FILES['images']['name'])) {
//Make Full Directory
if (!file_exists($uploaddir . '/full')) {
mkdir($uploaddir . '/full', 0775, true);
}

//Upload Full Size Thumbnails
foreach ($_FILES['images']['error'] as $key => $error) {
    if ($error == UPLOAD_ERR_OK) {
    $tmp_name = $_FILES['images']['tmp_name'][$key];
    $name = $_FILES['images']['name'][$key];

    //Max Height Width
$maxwidth = 100;

    //Read filetype  
        $i = strrpos($name,".");  
    if (!$i) { return ""; }  
    $l = strlen($name) - $i;  
    $extension = substr($name,$i+1,$l);  
    $extension = strtolower($extension);

    if ($extension=="jpg" || $extension=="jpeg" || $extension=="pjpeg" ) {$modifiedimage = imagecreatefromjpeg($tmp_name);} 
elseif ($extension=="png") {$modifiedimage = imagecreatefrompng($tmp_name);} 
elseif ($extension=="gif") {$modifiedimage = imagecreatefromgif($tmp_name);}  

list($width,$height)=getimagesize($tmp_name);  

    //Change dimensions  
    $newwidth = $maxwidth;  
    $newheight = ($height/$width)*$newwidth;  

//Create Image And Copy
    $newdim = imagecreatetruecolor($newwidth,$newheight);  
    imagecopyresampled($newdim,$modifiedimage,0,0,0,0,$newwidth,$newheight,$width,$height);  
    imagejpeg($modifiedimage,$uploaddir . '/full/' . $name,60);  

    // Remove temp images  
    imagedestroy($modifiedimage);  
    imagedestroy($newdim);  

    //move_uploaded_file($tmp_name, $uploaddir . '/full/' . $name);
echo '<span class="mainpagefontadmin">Project Photo Uploaded - Data Saved to: ' . $uploaddir . '/full/' . $name . '</span><br>';

    }
}
4

0 回答 0