2011-06-09 35 views
1

我使用了一個圖片上傳腳本,該腳本現在已經停止工作,現在我的主機已經關閉了register_globals。但是,我不知道如何在沒有它的情況下使其工作。如果你能幫助我,我會很高興。這裏的代碼:沒有register_globals的圖片上傳

  $uploadedfile = $_FILES['photo']['tmp_name']; 
      $src = imagecreatefromjpeg($uploadedfile); 

      // get the date from EXIF data 
      $exif = exif_read_data($uploadedfile, 0, true); 
      foreach ($exif as $key => $section) { 
       foreach ($section as $name => $val) { 
        if ($name == 'DateTimeOriginal') { 
         $the_filename = explode(" ", $val); 
         $the_filenamedate = str_replace(":", "", $the_filename[0]); 
         $the_filenametime = str_replace(":", "", $the_filename[1]); 
         $newfilename = $the_filenamedate."-".$the_filenametime.".jpg"; 

         $the_datetime = explode(" ", $val); 
         $the_date = str_replace(":", "-", $the_datetime[0]); 
         $the_time = $the_datetime[1]; 
         $datetime = $the_date." ".$the_time; 

         $exif_db = 'y'; 
        } 
       } 
      } 
      // use current date and time if no exif data 
      if (empty($newfilename)) { 
       $newfilename = date("Ymd-His").".jpg"; 
       $datetime = date("Y-m-d H:i:s"); 
       $exif_db = 'n'; 
      } 

      // resize if necessary 
      list($width,$height) = getimagesize($uploadedfile); 
      if ($resize_it == 'y') { 
       if ($width > $maxwidth) { 
        $newwidth = $maxwidth; 
        $newheight = ($height/$width)*$newwidth; 
       } else { 
        $newwidth = $width; 
        $newheight = ($height/$width)*$newwidth; 
       } 
      } else { 
       $newwidth = $width; 
       $newheight = $height; 
      } 
      $tmp = imagecreatetruecolor($newwidth,$newheight); 
      imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); 

      $filename = $dirpath.$gal_id."/".$newfilename; 
      imagejpeg($tmp,$filename,100); 

      // create thumbnail 
      $uploadedthumb = $_FILES['photo']['tmp_name']; 
      $srcthumb = imagecreatefromjpeg($uploadedthumb); 
      list($widththumb,$heightthumb) = getimagesize($uploadedthumb); 
      if ($widththumb > $heightthumb) { 
       $newheightthumb = 100; 
       $newwidththumb = ($widththumb/$heightthumb)*$newheightthumb; 
      } elseif ($widththumb == $heightthumb) { 
       $newheightthumb = 100; 
       $newwidththumb = 100; 
      } elseif ($widththumb < $heightthumb) { 
       $newwidththumb = 100; 
       $newheightthumb = ($heightthumb/$widththumb)*$newwidththumb; 
      } else { 
       $newheightthumb = 100; 
       $newwidththumb = ($widththumb/$heightthumb)*$newheightthumb; 
      } 

      $tmpthumb = imagecreatetruecolor($newwidththumb,$newheightthumb); 
      imagecopyresampled($tmpthumb,$srcthumb,0,0,$src_top,$src_left,$newwidththumb,$newheightthumb,$widththumb,$heightthumb); 
      $thumbname = $dirpath.$gal_id."/zth_".$newfilename.".jpg"; 
      imagejpeg($tmpthumb,$thumbname,100); 

      // free memory, destroying the source's and the pic's canvas 
      imagedestroy($srcthumb); 
      imagedestroy($tmpthumb); 
      imagedestroy($src); 
      imagedestroy($tmp); 

在此先感謝!

+0

你有什麼關於error_log的嗎? – 2011-06-09 09:29:32

+1

如果您添加發布數據的html表單,或者發送數據,那麼它非常有用。Register_globals自動將$ _GET $ _POST和$ _SESSION變量轉換爲全局變量,其中$ _POST ['id']變爲$ id 。要做到沒有register_globals,你必須更新所有變量引用$ _POST ['id'],例如 – 2011-06-09 09:36:34

回答

3

使用$ _POST數組讀取張貼的表單域。名爲emil的字段將具有PHP變量$_POST['emil']中的值,而不是$emil。你必須改變你閱讀表單域的所有實例。

這同樣適用於在查詢字符串,這是現在在$_GET發現,餅乾$_COOKIE和會話變量$_SESSION變量。

+0

謝謝你的解釋!我意識到我實際上在每個地方都使用'$ _POST','$ _GET'和'$ _FILES',所以不能成爲腳本無法工作的問題。現在我比以前更加無法了......:/ – rayne 2011-06-09 09:43:17

+0

更新:我的主機剛告訴我,我應該激活register_globals,那麼它應該工作。但是我仍然不知道爲什麼沒有它就無法工作。 – rayne 2011-06-09 13:21:04