2010-03-20 97 views
0

Hallo 我想上传一个文件。脚本应该拍摄图像,调整大小并上传。 但似乎有任何未知的我上传错误。文件无故上传丢失

下面的代码

define ("MAX_SIZE","2000");  // maximum size for uploaded images 
    define ("WIDTH","107"); // width of thumbnail 
    define ("HEIGHT","107"); // alternative height of thumbnail (portrait 107x80) 
    define ("WIDTH2","600"); // width of (compressed) photo 
    define ("HEIGHT2","600"); // alternative height of (compressed) photo (portrait 600x450) 

    if (isset($_POST['Submit'])) { 
    // iterate thorugh all upload fields 
    foreach ($_FILES as $key => $value) { 

     //read name of user-file 
     $image = $_FILES[$key]['name']; 
     // if it is not empty 
     if ($image) { 
     $filename = stripslashes($_FILES[$key]['name']); // get original name of file from clients machine 
     $extension = getExtension($filename); // get extension of file in lower case format 
     $extension = strtolower($extension); 

     // if extension not known, output error 
     // otherwise continue 
     if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { 
      echo '<div class="failure">Fehler bei Datei '. $_FILES[$key]['name'] .': Unbekannter Dateityp: Es können nur Dateien vom Typ .gif, .jpg oder .png hochgeladen werden.</div>'; 
     } else { 
      // get size of image in bytes 
      // $_FILES[\'image\'][\'tmp_name\'] >> temporary filename of file in which the uploaded file was stored on server 
      $size = getimagesize($_FILES[$key]['tmp_name']); 
      $sizekb = filesize($_FILES[$key]['tmp_name']); 

      // if image size exceeds defined maximum size, output error 
      // otherwise continue 
      if ($sizekb > MAX_SIZE*1024) { 
      echo '<div class="failure">Fehler bei Datei '. $_FILES[$key]['name'] .': Die Datei konnte nicht hochgeladen werden: die Dateigröße überschreitet das Limit von 2MB.</div>'; 
      } else { 
      $rand = md5(rand() * time()); // create random file name 
      $image_name = $rand.'.'.$extension; // unique name (random number) 

      // new name contains full path of storage location (images folder) 
      $consname = "photos/".$image_name; // path to big image 
      $consname2 = "photos/thumbs/".$image_name; // path to thumbnail 

      $copied = copy($_FILES[$key]['tmp_name'], $consname); 
      $copied = copy($_FILES[$key]['tmp_name'], $consname2); 

      $sql="INSERT INTO photos (galery_id, photo, thumb) VALUES (". $id .", '$consname', '$consname2')" or die(mysql_error()); 
      $query = mysql_query($sql) or die(mysql_error()); 

      // if image hasnt been uploaded successfully, output error 
      // otherwise continue 
      if (!$copied) { 
       echo '<div class="failure">Fehler bei Datei '. $_FILES[$key]['name'] .': Die Datei konnte nicht hochgeladen werden.</div>'; 
      } else { 
       $thumb_name = $consname2; // path for thumbnail for creation & storage 
       // call to function: create thumbnail 
       // parameters: image name, thumbnail name, specified width and height 
       $thumb = make_thumb($consname,$thumb_name,WIDTH,HEIGHT); 
       $thumb = make_thumb($consname,$consname,WIDTH2,HEIGHT2); 
      } 
      } 
     } 
     } 
    } 
    // current image could be uploaded successfully 
    echo '<div class="success">'. $success .' Foto(s) erfolgreich hochgeladen!</div>'; 
    showForm(); // call to function: create upload form 
    } 

回答

1

可我们看到的PHP错误日志?


其实消息: '照片/ 03be646900419daa11eaa1d1af1fd024.jpg' 是不是有效的JPEG文件

是说了!该文件不是有效的JPEG,这是问题所在。

0

没有在任何日志文件中找到。

这是唯一的消息,是我所得到的直接错误消息:

警告:imagecreatefromjpeg()[function.imagecreatefromjpeg]:GD-JPEG:JPEG库报告不可恢复的错误:在/ 58/htdocs中/主页/intern/inc.function.php在线95

警告:imagecreatefromjpeg()[function.imagecreatefromjpeg]: '照片/ 03be646900419daa11eaa1d1af1fd024.jpg' 不在/ 58/htdocs中/主页/实习生/ INC有效的JPEG文件.function.php on line 95

警告:imagesx():提供的参数不是/ 58/htdocs/home中的有效图像资源在线页面/实习生/ inc.function.php 104

警告:imagesy():提供的参数不是在/58/htdocs/homepage/intern/inc.function.php有效的图片资源上线105

警告:被零除在/58/htdocs/homepage/intern/inc.function.php在线120上

警告:imagecreatetruecolor()[function.imagecreatetruecolor]:在/ 58/htdocs中/主页无效图像尺寸/intern/inc.function.php on line 123

警告:imagecopyresampled():提供的参数在/ 58/htdocs/homepage/intern/i中不是有效的图像资源nc.function.php 125线