Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.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_File - Fatal编程技术网

PHP-上载的文件内部函数错误

PHP-上载的文件内部函数错误,php,file,Php,File,各位Stackoverflow用户好!我有一个我并不真正理解的问题 我制作了一个简单的脚本来处理一些上传的附件 它循环浏览所有上传的图像,并调用save缩略图()函数保存图像 代码: if(count($_FILES['image']['name']) > 0) { for($i=0; $i<count($_FILES['image']['name']; $i++){ $targetPath = "../../resources/img/posts/";

各位Stackoverflow用户好!我有一个我并不真正理解的问题

我制作了一个简单的脚本来处理一些上传的附件


它循环浏览所有上传的图像,并调用
save缩略图()
函数保存图像

代码:

if(count($_FILES['image']['name']) > 0) {
    for($i=0; $i<count($_FILES['image']['name']; $i++){
        $targetPath =  "../../resources/img/posts/";
        $pendingId = uniqid();
        $targetName = $i . $pendingId . ".jpg";

        saveThumbnail($i, $targetPath, $targetName);
    }
}
function saveThumbnail($i, $targetPath, $targetName){

    $imgName=$_FILES['image']['name'][$i];
    $imgLoc=$_FILES['image']['tmp_name'][$i];

    if ($imgName == NULL || $imgLoc == NULL){
        exit(CustomFunctions::ErrorWithCode("001"));
    }

    $path_parts = pathinfo($imgName);
    $ext = $path_parts['extension'];
    if ($ext != "png" && $ext != "jpg" && $ext != "gif" && $ext != "jpeg"){
        exit(CustomFunctions::ErrorWithCode("002"));
    }

    if (($img_info = getimagesize($imgLoc)) === FALSE)
      exit(CustomFunctions::ErrorWithCode("003"));

    switch ($img_info[2]) {
      case IMAGETYPE_GIF  : $src = imagecreatefromgif($imgLoc);  break;
      case IMAGETYPE_JPEG : $src = imagecreatefromjpeg($imgLoc); break;
      case IMAGETYPE_PNG  : $src = imagecreatefrompng($imgLoc);  break;
      default : exit(CustomFunctions::ErrorWithCode("004"));
    }



    // Fix Rotation
    $exif = exif_read_data($imgLoc);
    if (!empty($exif['Orientation'])) {
      switch ($exif['Orientation']) {
          case 3:
              $src = imagerotate($src, -180, 0);
              break;
          case 6:
              $src = imagerotate($src, 90, 0);
              break;
          case 8:
              $src = imagerotate($src, -90, 0);
              break;
      } 
    }



    $ratio = $img_info[0]/$img_info[1]; // width/height

    if( $ratio > 1) {
        $width = 500;
        $height = 500/$ratio;
    }
    else {
        $width = 500*$ratio;
        $height = 500;
    }



    $imgLocJPG = imagecreatetruecolor($width,$height);
    imagecopyresampled($imgLocJPG,$src,0,0,0,0,$width,$height,$img_info[0],$img_info[1]);
    imagedestroy($src);
    if(!imagejpeg($imgLocJPG, $targetPath . $targetName, 100)){
       exit(CustomFunctions::ErrorWithCode("005"));
    }

    // Destroy images
    imagedestroy($imgLocJPG);
    imagedestroy($imgLoc);



}
*如果**我将函数的内容放在
保存缩略图(“image”、$I、$targetPath、$targetName)行中,而不是放在
行中,则一切正常

否则,如果我使用该函数,它将失败,代码将返回
“\n”

有人知道为什么吗