[英]How can i get image dimensions after upload with jQuery File Upload?
When i try to upload a file via jQuery File Upload i am taking below response. 当我尝试通过jQuery File Upload上传文件时,我的回答如下。
Is it posible to add image dimensions to this result like width: 300px
and height: 400px
? 是否可以在此结果中添加图像尺寸,例如
width: 300px
和height: 400px
? I try to edit UploadHandler.php
for that need but i can't success. 我尝试根据需要编辑
UploadHandler.php
,但无法成功。 There is a function called set_additional_file_properties
in UploadHandler.php
. set_additional_file_properties
中有一个名为set_additional_file_properties
的UploadHandler.php
。 I tried to add a custom variable to the function but it fails because i think this function called before the file upload process. 我试图向该函数添加一个自定义变量,但是它失败了,因为我认为在文件上传过程之前调用了该函数。 It even could not find the file to get dimensions.
它甚至找不到要获取尺寸的文件。 I don't know why probably i am looking to wrong side of the document.
我不知道为什么我可能会寻找文档的错误部分。
protected function set_additional_file_properties($file) {
$file->dimensions = file_exists($file->url);
$file->deleteUrl = $this->options['script_url']
.$this->get_query_separator($this->options['script_url'])
.$this->get_singular_param_name()
.'='.rawurlencode($file->name);
$file->deleteType = $this->options['delete_type'];
if ($file->deleteType !== 'DELETE') {
$file->deleteUrl .= '&_method=DELETE';
}
if ($this->options['access_control_allow_credentials']) {
$file->deleteWithCredentials = true;
}
}
protected function set_additional_file_properties($file) {
$a = getimagesize(realpath(dirname($file->url))."/".$file->name);
$width = $a[0];
$height = $a[1];
if ($a) {
$file->width = $width;
$file->height = $height;
}
...
}
If I get your problem (you want to add width and height information to the image on the server side) then this should help: 如果遇到您的问题(您想在服务器端的图像上添加宽度和高度信息),则应该会有所帮助:
http://php.net/manual/function.getimagesize.php http://php.net/manual/function.getimagesize.php
Returns an array with up to 7 elements.
返回最多包含7个元素的数组。 Not all image types will include the channels and bits elements.
并非所有图像类型都将包含通道和位元素。 Index 0 and 1 contains respectively the width and the height of the image.
索引0和1分别包含图像的宽度和高度。
=> getimagesize($file) => getimagesize($ file)
Only need to change UploadHandler.php
file in set_additional_file_properties($file)
function for the following: 只需更改
UploadHandler.php
内容的set_additional_file_properties($file)
函数中的set_additional_file_properties($file)
:
protected function set_additional_file_properties($file) {
$filesize = getimagesize("files/".$file->name); //'files' folder is default folder to upload
$width = $filesize[0];
$height = $filesize[1];
if ($filesize) {
$file->width = $width;
$file->height = $height;
}
$file->deleteUrl = $this->options['script_url']
.$this->get_query_separator($this->options['script_url'])
.$this->get_singular_param_name()
.'='.rawurlencode($file->name);
$file->deleteType = $this->options['delete_type'];
if ($file->deleteType !== 'DELETE') {
$file->deleteUrl .= '&_method=DELETE';
}
if ($this->options['access_control_allow_credentials']) {
$file->deleteWithCredentials = true;
}
}
just added these lines: 刚刚添加了以下几行:
$filesize = getimagesize("files/".$file->name); //'files' folder is default folder to upload
$width = $filesize[0];
$height = $filesize[1];
if ($filesize) {
$file->width = $width;
$file->height = $height;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.