2013-02-03 42 views
1

我有一個網站,我已經給了我的用戶上傳他們的圖片的選項,我設置了一個條件,如他們沒有選擇任何文件上傳和如果他們點擊上傳按鈕而沒有選擇圖片,他們會得到一個警告框,但除此之外,我的網站正在顯示我正在粘貼的錯誤。exif_imagetype()[function.exif-imagetype]:文件名不能爲空

警告:exif_imagetype()[function.exif-IMAGETYPE]:文件名不能在/mounted-storage/home98a/sub009/sc61374-HGPS/sitakalyanam.com/newsita/php4upload.class.php是空的上線86

以及線86的代碼我附上..

function _doSafeUpload() 
{ 
    preg_match('/\.([a-zA-Z]+?)$/', $this->_params['name'], $matches); 
    if (exif_imagetype($this->_params['tmp_name']) &&  in_array(strtolower($matches[1]), $this->_types)) 
    { 
     if ($this->_params['size'] > $this->_maxsize) 
      $this->_errors[] = $this->_lang['E_SIZE']; 
     else 
      $this->_im_status = true; 

     if ($this->_im_status == true) 
     { 
      $ext = substr($this->_params['name'], -4); 
      $this->new_name = md5(time()).$ext; 

      move_uploaded_file($this->_params['tmp_name'], $this-  >_upload_dir.$this->new_name); 

     $this->imgurl =$this->new_name; 

     //$this->imgurl = .$this->new_name; 


     } 
    } 
    else 
     $this->_errors[] = $this->_lang['E_TYPE']; 
} 

我不想表現出越來越顯示的錯誤在我的網頁我的用戶。相反,我想向他們展示或親密他們,他們沒有選擇任何文件上傳。

我在這裏上傳完整code.but沒有錯誤,如果上傳文件選擇錯誤來,只有當沒有文件choosen上傳

<?php 
    /* 

    - PHP4 Image upload script 

    */ 

    class imageupload 
    { 
    //pblic variables 
    var $path = ''; 
    var $errorStr = ''; 
    var $imgurl = ''; 

    //private variables 
    var $_errors = array(); 
    var $_params = array(); 
    var $_lang = array(); 
    var $_maxsize = 1048576; 

    var $_im_status = false; 

    //public methods 
    function imageupload() 
{ 
    //require 'photouploadconfig.php'; 

    if($_GET['Choice']=="1") 
    {   
    require 'Photouploddir1.php'; 
    } 
    elseif ($_GET['Choice']=="2") 
    { 
    require 'Photouploddir2.php'; 
    } 
    elseif ($_GET['Choice']=="3") 
    { 
    require 'Photouploddir3.php'; 
    } 
    elseif ($_GET['horoschoice']=="1") 
    { 
    require 'horosuploaddir.php'; 
    } 
    elseif ($_GET['videoChoice']=="5") 
    { 
    require 'videouploaddir.php'; 
    } 


     $this->_types = $types; 
     $this->_lang = $lang; 
    $this->_upload_dir = $upload_dir; 
    $this->_maxsize = $maxsize; 

     $this->path = $PHP_SELF; 

     if (is_array($_FILES['__upload'])) 
     { 
      $this->_params = $_FILES['__upload']; 
      if (function_exists('exif_imagetype')) 
       $this->_doSafeUpload(); 
     else 
       $this->_doUpload(); 

      if (count($this->_errors) > 0) 
       $this->_errorMsg(); 
     } 
    } 

    function allowTypes() 
    { 
     $str = ''; 
     if (count($this->_types) > 0) { 
      $str = 'Allowed types: ('; 
      $str .= implode(', ', $this->_types); 
      $str .= ')'; 
     } 

     return $str; 
    } 

     // private methods 
    function _doSafeUpload() 
    { 
     preg_match('/\.([a-zA-Z]+?)$/', $this->_params['name'], $matches); 
     if (exif_imagetype($this->_params['tmp_name']) == exif_imagetype($this-   >_params[''])) 
     { 
      print '<script type="text/javascript">'; 
       print 'alert("Opps! You Have Not Choosen Any Photos For Uploading.Kindly   Select Choose File Tab For Uploading.")'; 
       print '</script>'; 
       print "<script>"; 
       print " self.location='photoupload.php';"; 
       print "no photo uploaded"; 
        print "</script>"; 
     } 
     if (exif_imagetype($this->_params['tmp_name']) && in_ a  rray(strtolower($matches[1]), $this->_types)) 
     { 
      if ($this->_params['size'] > $this->_maxsize) 
      $this->_errors[] = $this->_lang['E_SIZE']; 
     else 
      $this->_im_status = true; 

     if ($this->_im_status == true) 
     { 
      $ext = substr($this->_params['name'], -4); 
      $this->new_name = md5(time()).$ext; 

       move_uploaded_file($this->_params['tmp_name'], $this->_u  pload_dir.$this->new_name); 

      $this->imgurl =$this->new_name; 

     //$this->imgurl = .$this->new_name; 


     } 
      } 
     else 
     $this->_errors[] = $this->_lang['E_TYPE']; 
       } 

     function _doUpload() 
     { 
    preg_match('/\.([a-zA-Z]+?)$/', $this->_params['name'], $matches); 
    if(in_array(strtolower($matches[1]), $this->_types)) 
    { 
      if ($this->_params['size'] > $this->_maxsize) 
      $this->_errors[] = $this->_lang['E_SIZE']; 
     else 
      $this->_im_status = true; 

     if ($this->_im_status == true) 
     { 
      $ext = substr($this->_params['name'], -3); 
       $this->new_name = md5(time()).$ext; 

       move_uploaded_file($this->_params['tmp_name'], $this->_u   pload_dir.$this->new_name); 

       $this->imgurl = ''.$this->new_name; 

    //$this->imgurl = ''.$this->_upload_dir.''.$this->new_name; 
    //$this->imgurl = ''.$this->new_name; 

       //$this->imgurl = $this->_upload_dir.'/'.$this->new_name; 



      } 
     } 
    else 
     $this->_errors[] = $this->_lang['E_TYPE']; 
     } 

      function _errorMsg() 
      { 
     $this->errorStr = implode('<br />', $this->_errors); 
      } 
      } 

      ?> 

回答

0

此:$this->_params['tmp_name']顯然並未包含文件路徑。通常你會從$_FILES['name']['tmp_name']得到這個數據但是你有某種抽象,這使得很難看到問題出在哪裏。

+0

嗨,我已經粘貼完整的代碼。如果用戶選擇任何文件沒有錯誤彈出,但我錯誤的用戶,如果他們不選擇任何文件上傳然後警告錯誤顯示在用戶端的網頁屏幕.... – shijumax

相關問題