PHP - 文件上传[POST]:无法处理

时间:2016-09-08 13:58:29

标签: php image file-upload

尝试上传图片/文件时出错。图像已上传但我始终存在此错误。

[08-Sep-2016 09:45:29 America/New_York] PHP Notice:  File Upload [POST]: Cannot process $_FILES[products_image_resize]['tmp_name'] in /home/www/boutique/includes/OM/Upload.php on line 73

第73行o上传课程

if ( isset($_FILES[$this->_file]) ) {
        if ( isset($_FILES[$this->_file]['tmp_name']) && !empty($_FILES[$this->_file]['tmp_name']) && is_uploaded_file($_FILES[$this->_file]['tmp_name']) && ($_FILES[$this->_file]['size'] > 0) ) {
          $this->_upload = array('type' => 'POST',
                                 'name' => $_FILES[$this->_file]['name'],
                                 'size' => $_FILES[$this->_file]['size'],
                                 'tmp_name' => $_FILES[$this->_file]['tmp_name']);
        } else {
          trigger_error('File Upload [POST]: Cannot process $_FILES[' . $this->_file . '][\'tmp_name\']');
        }
      }

在我的班级产品中:function getImage()

// load originale image
      $image = new Upload('products_image_resize', DIR_FS_CATALOG_IMAGES  . $dir_products_image, null, array('gif', 'jpg', 'png'));

      if ( $image->check() && $image->save() ) {
        $error = false;
      }

      if ( $error === false ) {
        $sql_data_array['image'] = $dir_products_image . $separator . $image->getFilename();
      } else {
        $sql_data_array['image'] = '';
        $OSCOM_MessageStack->add(ERROR_CATALOG_IMAGE_DIRECTORY_NOT_WRITEABLE, 'warning');
      }

称为

// image
      $this->getImage();

在我的html文件中,我的表单

<form name="new_product" action="http://boutique/admin/index.php?Products&cPath=&pID=3&action=update_product" method="post" enctype="multipart/form-data">

我的测试

//print_r($_FILES[$this->_file]);
// Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) - no files
//Array ( [name] => shopping-bag.png [type] => image/png [tmp_name] => /tmp/phpOg7mnD933577 [error] => 0 [size] => 933577 )  - files

print_r($_FILES[$this->_file]['tmp_name']); // 0 - no files
print_r($_FILES[$this->_file]['size']); // 0 - no file;

print_r($_FILES[$this->_file]['tmp_name']); // //tmp/phpOg7mnD933577 - files
print_r($_FILES[$this->_file]['size']); // /tmp/phpOg7mnD933577g - file;

测试线

if ( isset($_FILES[$this->_file]['tmp_name']) && !empty($_FILES[$this->_file]['tmp_name']) && is_uploaded_file($_FILES[$this->_file]['tmp_name']) && ($_FILES[$this->_file]['size'] > 0) ) {

替换为

if (!empty($_FILES[$this->_file]['tmp_name'])) { // works
   if (is_uploaded_file($_FILES[$this->_file]['tmp_name'])) { // File Upload [POST]: Cannot process $_FILES[products_image_resize]['tmp_name']
   if (($_FILES[$this->_file]['size'] > 0)) {  //works

1 个答案:

答案 0 :(得分:0)

在您的表单中,更改

<form name="new_product" action="http://boutique/admin/index.php?Products&cPath=&pID=3&action=update_product" method="post" enctype="multipart/form-data">

<form name="new_product" action="http://boutique/admin/index.php?Products&cPath=&pID=3&action=update_product" method="post" enctype="application/x-www-form-urlencoded">