[英]Uploading large images using jQuery and PHP
I am using jQuery and PHP to upload images to the server and return a JSON of the cropped image. 我正在使用jQuery和PHP将图像上传到服务器,并返回裁剪图像的JSON。
My JavaScript code is: 我的JavaScript代码是:
$('document').ready(function () {
$('#stat').hide();
$('#file').on('change', function () {
var fd = new FormData($('#target')[0]);
$('#display > img').remove();
$('#stat').show();
$.ajax({
url: '<?php echo base_url('crop/upload') ?>',
type: "POST",
data: fd,
timeout: 1000 * 100,
contentType: false,
processData: false,
success: function (data, textStatus, jqXHR) {
$('#stat').hide();
$('div > img').remove();
console.log(data);
console.log(data[1].thumb);
$('#display > img').remove();
var img = $('<img>');
img.attr('src', data[1].thumb);
img.appendTo('#display')
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(textStatus);
},
dataType: 'json'
})
})
})
But whenever the image size is larger than 2 MB the, I see a parse error in the JS console. 但是,只要图像大小大于2 MB ,我就会在JS控制台中看到解析错误。 I tried to set a timeout, but it didn't work.
我试图设置一个超时,但是没有成功。
What is the problem? 问题是什么? Does the browser sets a timeout?
浏览器是否设置超时?
How can I enable users to upload large images without a parse error ? 如何使用户上载没有解析错误的大图像?
increasing the memory allocated for PHP will solve the issue. 增加分配给PHP的内存将解决此问题。
you can do it by: 您可以通过以下方式做到:
1- Edit php.ini 1-编辑php.ini
memory_limit = 128M
; memory_limit = 128M
; Or put code below to .htaccess 或将以下代码放入.htaccess
php_value memory_limit 128M
2-If you oftenly get this error and solution above isn't work, contact your host. 2-如果您经常收到此错误,而上述解决方案不起作用,请与您的主机联系。 In most shared hosting, there is maximum memory_limit.
在大多数共享主机中,有最大的memory_limit。 You can't set memory-limit to 64Mb if you get max 32Mb.
如果获得最大32Mb,则不能将内存限制设置为64Mb。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.