0

hi all when using exif_imagetype() [function.exif-imagetype]: ユーザーが何もアップロードせずに送信ボタンを押した場合に画像をチェックする関数 exif 関数は、Web ページ自体にエラーを返します。私の質問は、このエラーを取り除く方法です。以下にエラーを貼り付けています

Warning: exif_imagetype() [function.exif-imagetype]: Filename cannot be empty in /mounted-    storage/home98a/sub009/sc61374-HGPS/sitakalyanam.com/newsita/php4upload.class.php on line 88
 <?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']) && 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->_up     load_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-    >_upload_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);
    }
}

?>
4

2 に答える 2

0

ユーザーがファイルをアップロードしたかどうかを確認していないため、そのメッセージを受け取っています。ユーザーがファイルをアップロードしない場合$_FILES、空の配列になります。

つまり$this->_params['tmp_name']存在しないということです。ファイルがアップロードされたと仮定するだけでなく、ファイルがアップロードされたかどうかを確認する必要があります。

のサイズを確認するだけです$_FILES

if(count($_FILES) === 0){
    echo "no file uploaded";
}
于 2013-02-04T15:28:09.377 に答える
0

コードをこれに変更してから試してください

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

        if (count($this->_errors) > 0)
            $this->_errorMsg();
    }
于 2014-07-01T04:28:48.397 に答える