Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.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_Jquery_File Upload - Fatal编程技术网

PHP图像上载和调整大小错误

PHP图像上载和调整大小错误,php,jquery,file-upload,Php,Jquery,File Upload,我在网站上查找问题的解决方案,但找不到答案。希望有人能在这方面帮助我: 我有一个脚本,可以在不刷新页面的情况下上传图像并调整其大小。我在网上找到了它,并根据我的使用情况进行了调整。脚本可以在下面找到 我的问题: 首先,upload.php脚本工作正常,但我知道错误号为9 我自己是怎么解决的: 在本地计算机和服务器上尝试了它,两者都给出了相同的错误号9 删除了所有$\u POST并设置了“静态”变量,但不起作用,仍然得到了第9个变量 有人能帮我吗,tnx 格茨 懦夫 upload.php <

我在网站上查找问题的解决方案,但找不到答案。希望有人能在这方面帮助我:

我有一个脚本,可以在不刷新页面的情况下上传图像并调整其大小。我在网上找到了它,并根据我的使用情况进行了调整。脚本可以在下面找到

我的问题:

首先,upload.php脚本工作正常,但我知道错误号为9

我自己是怎么解决的:

  • 在本地计算机和服务器上尝试了它,两者都给出了相同的错误号9
  • 删除了所有$\u POST并设置了“静态”变量,但不起作用,仍然得到了第9个变量
  • 有人能帮我吗,tnx

    格茨

    懦夫

    upload.php

    <?php
    /************************************************************            
     *-----------------------------------------------------------
     * Version  : 0.2
     * Author  : Wim Selles        
     * Date  : 2009-12-04
     * History  : Adjusted to use with AJAX upload
     *     Added check for allowed extension
     *     Added change filename to time 
     *     of uploading
     *-----------------------------------------------------------
     * Version  : 0.1
     * Author  : Eris        
     * Date  : 2005-11-19
     * History  : Initial version
     * Source  : http://www.phphulp.nl/php/scripts/9/464/
     *-----------------------------------------------------------
     ************************************************************/
    
    if(!empty($_FILES['file'])){
     //---- filename generated by the server when uploading a file
     $tempfile     =  $_FILES['file']['tmp_name'];
     //---- directory with the final location 
     $dir      =  $_POST['uploadPath'];
     //---- Get the extension of the file    
     $ext      =  strtolower(substr(strrchr($_FILES['file']['name'], '.'), 1));
     $ext_image    =  array("gif", "jpg","jpeg","png");
     //---- new filename is time and extention
     $file      =  time().".".$ext;
     //---- resize / max height and width of image
     list($height,$width) = explode(',',$_POST['imageMess']);
     //---- The max filesize
     $limit_size    = $_POST['imageSize']*1024*1024;
    
     //---- error = 1 => file is not uploaded
     //---- error = 2 => No image file
     //---- error = 3 => File uploaded
     //---- error = 4 => Error during move upload file
     //---- error = 5 => File allready exsits
     //---- error = 6 => Error resizing jpg
     //---- error = 7 => Error resizing gif
     //---- error = 8 => Error resizing png
     //---- error = 9 => Imagecreate error for jpg
     //---- error = 10 => Resized (not error, but succes ;-))
     //---- error = 11 => Imagecreate error for gif 
     //---- error = 12 => Imagecreate error for png 
     //---- error = 13 => Filetype not allowed
    
     //----check if the file is realy uploaded
     if(filesize($tempfile)>=$limit_size){
      $error = 14;
     }elseif(!is_uploaded_file($tempfile)){
      $error = 1;
     }elseif(!in_array($ext, $ext_image)){
      //---- Check if file is allowed, if not, then show error
      $error = 13;
     }else{
      //---- get the dimensions of the file
      if(!$dim = getimagesize($tempfile)){
       $error = 2;
      }else{    
       //---- 0 = width 
       //---- 1 = height
       //---- 2 = type
       //---- we want to calculte if it is bigger then the maxsize if not keep it easy --> upload it
       if($dim[0] < $width && $dim[1] < $height){
        //----move upload file
        if(!file_exists($dir.$file)){
         if(@move_uploaded_file($tempfile,$dir.$file)){
          $error = 3;
         }else{
          $error = 4;    
         }
        }else{
         $error = 5;   
        }        
       }else{
        //---- we have to resize :(
        if($dim[0] > $dim[1]){
         $prop = $width / $dim[0];
         $dims[0] = $width;
         $dims[1] = round($dim[1] * $prop); 
        }else{
         $prop = $height / $dim[1];
         $dims[1] = $height;
         $dims[0] = round($dim[0] * $prop); 
        }
        //---- we know the new size
        if($dim[2] == 2){
         if(!$mimage = @imagecreatefromjpeg($tempfile)){
          $error = 6;
         }
        }
        //---- we know the new size
        if($dim[2] == 1){
         if(!$mimage = @imagecreatefromgif($tempfile)){
          $error = 7;
         }
        }
        //---- we know the new size
        if($dim[2] == 3){
         if(!$mimage = @imagecreatefrompng($tempfile)){
          $error = 8;
         }
        }
        $im = @imagecreatetruecolor($dims[0],$dims[1]);
        @imagecopyresampled($im, $mimage, 0, 0, 0, 0, $dims[0], $dims[1], $dim[0], $dim[1]);
    
        if(!file_exists($dir.$file)){
         if($dim[2] == 2){
          if(!@imagejpeg($im,$dir.$file,100)){
           $error = 9; // This is the error i still get
          }else{
           $error = 10;    
          }    
         }    
         if($dim[2] == 1){
          if(!@imagegif($im,$dir.$file)){
           $error = 11;
          }else{
           $error = 10;    
          }    
         }
    
         if($dim[2] == 3){
          if(!@imagepng($im,$dir.$file)){
           $error = 12;
          }else{
           $error = 10;      
          }    
           }
        }else{
         $error = 5;       
        }
        imagedestroy($im);
        imagedestroy($mimage);  
        //---- end resize
       }  
      }
     }
     ?>
    
     <script language="javascript" type="text/javascript">
         parent.stopUpload(<?php echo $error; ?>,'<?php echo "intranet/admin/uploadedImages/".$file;?>');
      //alert(<?php //echo $error2;?>);
        </script>
    
        <?php
    }
    ?>
    
    表格:

    <form action="intranet/admin/upload.php" method="post" enctype="multipart/form-data" target="upload_target" id="submitfile">
    
                    <img id="profilePhoto" src="intranet/admin/uploadedImages/unknown.png" height="100px"/>
    
                    <img id="f1_upload_process" src="include/css/images/ajax-loader3.gif" />
    
                    <br />
        <br />
    
        <input name="file" type="file" id="fileLocation" />
        <input type="submit" name="submitBtn" value="Upload" />
    
        <br />
        <br />
    
        <p class="text">Toegestane extensies: *.jpg | *.gif | *.png</p>
    
        <br />
    
        <p id="result"></p>
    
       </form>
    
       <iframe id="upload_target" name="upload_target" style="width:0;height:0;border:0px solid #fff;"></iframe>
    
    
    



    toegestan扩展名:*.jpg*gif*png



    尝试删除此行中的@:

     if(!@imagejpeg($im,$dir.$file,100)){
    

    它抑制imagejpeg抛出的错误。如果没有它,您可能会看到问题所在。

    从以下行中删除
    @

      if(!@imagejpeg($im,$dir.$file,100)){
    
    @
    抑制错误。如果它被删除并且启用了
    display\u errors
    ,您应该会看到更具描述性的错误消息

    我猜是由于权限不足,
    imagejpeg()
    无法写入该文件。

    该死

    我很愚蠢:(

    正如我建议的那样,我去掉了@,亲眼看到了我做错了什么

    错误出现在我的目录结构中,如下所示

    |主文件夹| |_|子文件夹| |upload.php ||图像文件夹|

    $dir=$\u POST['uploadPath'];
    是一个将文件移动到“mainfolder/subfolder/imageFolder”的文件夹,但它必须是“imageFolder/”,因为我在“subfolder”中使用upload.php文件

    谢谢你的帮助

    格尔茨


    Wim

    如果结果是内存问题(始终是我的第一个赌注),请记住3000 x 3000像素JPG占用的内存不是9 MB,而是至少3 x 3000 x 3000=27 MB。
      if(!@imagejpeg($im,$dir.$file,100)){