Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 上载时调整图像大小_Php_Mysql - Fatal编程技术网

Php 上载时调整图像大小

Php 上载时调整图像大小,php,mysql,Php,Mysql,我的代码有什么问题?上传时,我需要调整图像大小,变量$new_width和$new_height是图像的尺寸。我认为$newname变量中存在问题,因为在我添加:D之前它是有效的 <meta charset="utf-8" /> <?php include 'config.php'; mysqli_set_charset($db, 'utf8'); $id = $_COOKIE["id"]; if (isset($_POST["action"])){ $newname

我的代码有什么问题?上传时,我需要调整图像大小,变量$new_width和$new_height是图像的尺寸。我认为$newname变量中存在问题,因为在我添加:D之前它是有效的

<meta charset="utf-8" /> 
<?php
include 'config.php';
mysqli_set_charset($db, 'utf8');
$id = $_COOKIE["id"];
if (isset($_POST["action"])){
    $newname = substr(md5(rand() * time()), 5,10);
    $folder = "image/";
    $folder2 = "image/thumb/";

    $filetmp = $_FILES["filep"]["tmp_name"];
    $filename = $_FILES["filep"]["name"];
    $filetype = $_FILES["filep"]["type"];
    $filesize = $_FILES["filep"]["size"];
    $fileinfo = getimagesize($_FILES["filep"]["tmp_name"]);
    $filewidth = $fileinfo[0];
    $fileheight = $fileinfo[1];
    $filepath = "$folder".$newname.$filename;
    $filepath_thumb = "$folder".$filename;

    if($filetmp == ""){
        echo "Upload image";
    }
    else {
        if($filesize > 2097152){            
            echo "Less then 2 mb";          
        }
        else{
            if($filetype != "image/jpeg" && $filetype != "image/png" 
                && $filetype != "image/gif" && $filetype != "image/jpg"){

                echo ".jpeg, .jpg, .gif, .png";
            }
            else{               
                move_uploaded_file($filetmp,$filepath);

                if($filetype == "image/jpeg"){
                    $imagecreate = "imagecreatefromjpeg";
                    $imageformat = "imagejpeg";
                }
                if($filetype == "image/png"){                        
                    $imagecreate = "imagecreatefrompng";
                    $imageformat = "imagepng";
                }
                if($filetype == "image/gif"){                        
                    $imagecreate= "imagecreatefromgif";
                    $imageformat = "imagegif";
                }
                if($filetype == "image/jpg"){                        
                    $imagecreate= "imagecreatefromjpg";
                    $imageformat = "imagejpg";
                }   

                $new_width = "200";
                $new_height = "150";

                $image_p = imagecreatetruecolor($new_width, $new_height);
                $image = $imagecreate($filepath); //photo folder

                imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $filewidth, $fileheight);                     
                $imageformat($image_p, $filepath_thumb);//thumb folder  

                $res = mysqli_query($db, "UPDATE Imager SET Cover='".$newname.$filename."' WHERE IDImg ='$id'");

                if($res) {
                    echo "Good.";
                }
                else {
                    echo "Not Good.";
                }
            }
        }
    }
}

header( "Refresh:2; url=img.php", true, 303);
?>


我建议您使用类似的库—它将使此过程更加简单