Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.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_Image_File Upload - Fatal编程技术网

无法找到使用PHP调整图像大小的方法

无法找到使用PHP调整图像大小的方法,php,image,file-upload,Php,Image,File Upload,我想调整上传到200*200像素的任何图像的大小。我已经在网络上查看了所有脚本,发现了很多,但无法使用任何脚本。我不希望任何其他控件只是将其调整到特定大小 <!-<?php session_start();?> <?php session_start();?> <?php $u_name=birju;?> <?php require_once("mydb.php");?> <?php define ("MAX_SIZ

我想调整上传到200*200像素的任何图像的大小。我已经在网络上查看了所有脚本,发现了很多,但无法使用任何脚本。我不希望任何其他控件只是将其调整到特定大小

<!-<?php session_start();?>
<?php session_start();?>
<?php $u_name=birju;?>
<?php require_once("mydb.php");?>
<?php

         define ("MAX_SIZE","100"); 


         function getExtension($str) {
                 $i = strrpos($str,".");
                 if (!$i) { return ""; }
                 $l = strlen($str) - $i;
                 $ext = substr($str,$i+1,$l);
                 return $ext;
         }


         $errors=0;

          if(isset($_POST['Submit'])) 
         {
            $image=$_FILES['image']['name'];
            if ($image) 
            {
                $filename = stripslashes($_FILES['image']['name']);
                $extension = getExtension($filename);
                $extension = strtolower($extension);
         if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) 
                {
                    echo '<h1>Unknown extension!</h1>';
                    $errors=1;
                }
                else
                {
         $size=filesize($_FILES['image']['tmp_name']);

        if ($size > MAX_SIZE*1024)
        {
            echo '<h1>You have exceeded the size limit!</h1>';
            $errors=1;
        }

        $image_name = $u_name.'.'.$extension;
        $newname="images/".$image_name;
        $copied = copy($_FILES['image']['tmp_name'], $newname);
        if (!$copied) 
        {
            echo '<h1>Copy unsuccessfull!</h1>';
            $errors=1;
        }}}}

         $me=mysql_query("insert into img_upload values(\"\",\"$u_name\",\"$newname\")");
         if(!$me)
         {
             die("database query failed".mysql_error());
         }

?>

         <!--next comes the form, you must set the enctype to "multipart/frm-data" and use an input type "file" -->
         <form name="newad" method="post" enctype="multipart/form-data"  action="">
         <table>
            <tr><td><input type="file" name="image"></td></tr>
            <tr><td><input name="Submit" type="submit" value="Upload image"></td></tr>
         </table>   
         </form>
--> 

--> 

使用PHP GD查看timthumb:

,而不是关于将图像从tmp\u名称复制到新名称的代码使用:

$image = file_get_contents($_FILES['image']['tmp_name']);
$new_image = imagecreatetruecolor(200, 200);
imagecopyresampled($new_image, $image, 0, 0, 0, 0, 200, 200, imagesx($image), imagesy($image));
file_put_contents($newname, $new_image);

如果你要投反对票,请添加注释说明原因。我从网络上获得了各种Javascript来调整大小…它们提供了各种控件…但是我只是想在它存储到本地服务器文件夹之前将其调整到特定大小…难道不能在这段代码中再添加几行,以便可以专门调整图像大小吗?您还没有看得太远(或太深)足够地