exif_imagetype()[function.exif-imagetype]:文件名不能为空

时间:2013-02-03 03:12:12

标签: php

我有一个网站,我已经为我的用户提供了上传图片的选项,我设置了一个条件,如果他们没有选择任何文件进行上传,如果他们点击上传按钮而没有选择图片他们会得到一个警告框,但除此之外我的网站显示我在下面粘贴的错误。

  

警告:exif_imagetype()[function.exif-imagetype]:第86行/mounted-storage/home98a/sub009/sc61374-HGPS/sitakalyanam.com/newsita/php4upload.class.php中的文件名不能为空

我正在附加的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'];
}

我不想显示我的网页中为我的用户显示的错误。相反,我想向他们展示或亲密他们没有选择任何文件进行上传。

这里我正在上传完整的代码。但是如果选择上传文件则没有错误只有在没有选择上传文件的情况下才会出现错误

    <?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);
           }
           }

           ?>

1 个答案:

答案 0 :(得分:0)

这:$this->_params['tmp_name']显然不包含文件路径。通常你会从$_FILES['name']['tmp_name']获得这些数据但是你有某种抽象,这使得很难看出问题可能出在哪里。