开发者

File Upload drops with no reason

Hallo I want to make an file upload. The script should take the image, resize it and upload it. But it seems that there is any unknown to me error in the upload.

Here the code

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 
  }


Can we see the PHP error log?


Actually the message: 'photos/03be646900419daa11eaa1d1af1fd024.jpg' is not a valid JPEG file

is saying it! The file is not a valid JPEG, this is the problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜