首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >exif_imagetype() [函数.exif-图像类型]:

exif_imagetype() [函数.exif-图像类型]:
EN

Stack Overflow用户
提问于 2013-02-04 22:33:22
回答 2查看 1.4K关注 0票数 0

使用exif_imagetype()函数时,您好。exif -imagetype:用于检查图像的函数,如果用户没有上传任何内容,单击submit按钮,exif函数会在网页本身返回一个错误。我的问题是如何摆脱这个错误。我正在粘贴下面的错误

代码语言:javascript
复制
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
代码语言:javascript
复制
 <?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);
    }
}

?>
EN

回答 2

Stack Overflow用户

发布于 2013-02-04 23:28:09

你会收到这样的消息,因为你永远不会检查用户是否上传了文件,你只是假设他们上传了文件。当用户不上传文件时,$_FILES将是一个空数组。

这意味着$this->_params['tmp_name']将不复存在。你需要检查一个文件是否已经上传,而不是仅仅假设一个文件已经上传。

只需检查$_FILES的大小即可。

代码语言:javascript
复制
if(count($_FILES) === 0){
    echo "no file uploaded";
}
票数 0
EN

Stack Overflow用户

发布于 2014-07-01 12:28:48

将您的代码更改为以下代码,然后尝试

代码语言:javascript
复制
    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();
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14688911

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档