Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无法使用jQuery文件上传插件获取图像大小和类型,如何?_Php_Jquery_Zend Framework_Jquery File Upload_Image Upload - Fatal编程技术网

Php 无法使用jQuery文件上传插件获取图像大小和类型,如何?

Php 无法使用jQuery文件上传插件获取图像大小和类型,如何?,php,jquery,zend-framework,jquery-file-upload,image-upload,Php,Jquery,Zend Framework,Jquery File Upload,Image Upload,我正在使用jquery插件上传一些文件 我正在通过api将图片从一个域(客户端)上传到另一个域(服务器端) 图像似乎上传到服务器端的tmp目录中,但是$\u文件var不包含图像类型或大小 array (size=1) 'files' => array (size=5) 'name' => array (size=1) 0 => string '3.jpg' (length=5) 'type' =>

我正在使用jquery插件上传一些文件 我正在通过api将图片从一个域(客户端)上传到另一个域(服务器端)

图像似乎上传到服务器端的tmp目录中,但是
$\u文件
var不包含图像类型或大小

array (size=1)
  'files' => 
    array (size=5)
      'name' => 
        array (size=1)
          0 => string '3.jpg' (length=5)
      'type' => 
        array (size=1)
          0 => null
      'tmp_name' => 
        array (size=1)
          0 => string '/tmp/phpXyHG5T' (length=14)
      'error' => 
        array (size=1)
          0 => int 0
      'size' => 
        array (size=1)
          0 => null
js很简单

$('#fileupload').fileupload({
        dataType: 'json',
        url : 'http://server_side.com/requests/index/image-upload/',
        add: function (e, data) {
            data.context = $('#upload_button')
                .click(function () {
                    data.context = $('#upload_button').text('Uploading...');
                    data.submit();
                });
        },
        done: function (e, data) {
            console.log(data);
        }
    }).on('fileuploaddone', function (e, data) {
        console.log(data);
    }).on('fileuploadsubmit', function (e, data) {
        console.log(data);
    });
php方面

$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender(TRUE);

// initialize the upload
$uploadHandler = new Api_Model_UploadHandler();
$uploadHandler->initialize();
有什么想法吗?

我想出来了。 我正在使用Zend框架

问题是
$\u文件
Api\u模型上传处理程序
初始化后,如果您要求
tmp
图像,那么
$\u文件
会松开
大小
类型

因此,通过询问之前的图像似乎是可行的

无需检查文件是否存在

public function imageUploadAction()
{
    // in case some other crap goes wrong on the website, i want a clean json response
    error_reporting(0);

    $this->_helper->layout->disableLayout();
    $this->_helper->viewRenderer->setNoRender(TRUE);

    // get the request
    $request   = $this->getRequest();
    // get other params if you sent any

    $fileName = !empty($_FILES) ? $_FILES["files"]["name"][0] : '_';

    if (file_exists('tmp/' . $fileName)) {

        $upload = new Zend_File_Transfer_Adapter_Http();

        if (is_null($files)) {
            $files = $upload->getFileInfo();
        }

                // ... do a regular zend image upload
    }

    // initialize the upload
    $uploadHandler = new Api_Model_UploadHandler();
    $uploadHandler->initialize();

    return json_encode(array());
}