简体   繁体   English

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

[英]PHP - File Upload [POST]: Cannot process

I have an error when I try to upload an image / files. 我尝试上传图片/文件时出错。 The image is uploaded but I have always this error. 图像已上传,但我始终存在此错误。

[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

Line 73 o Upload class 第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\']');
        }
      }

Inside my class products : function getImage() 在我的类产品中: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');
      }

called

// image
      $this->getImage();

In my html files, my form 在我的html文件中,我的表单

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

My test 我的考试

//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;

line to test 线来测试

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) ) {

replaced by 取而代之

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

In your form, change 在你的表格中,改变

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

to

<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">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM