Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.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 限制要上载的图像文件的尺寸_Php_File Upload - Fatal编程技术网

Php 限制要上载的图像文件的尺寸

Php 限制要上载的图像文件的尺寸,php,file-upload,Php,File Upload,如何限制通过php脚本上载的图像的维度 我使用的是cakephp v 1.2您必须等待文件上传,然后调用以检查尺寸,如果尺寸太大,则打印错误 在上传完成之前,您无法检查大小。如果客户端没有可以看到文件系统的东西(如Java小程序),您无法提前知道它 你能做的最好的事情就是在上传文件之后,但在你做任何重要的事情之前,用它检查文件 list($width, $height) = getimagesize($_FILES['myfile']['tmp_name']); 不幸的是,您只能在上载后使用

如何限制通过php脚本上载的图像的维度


我使用的是cakephp v 1.2

您必须等待文件上传,然后调用以检查尺寸,如果尺寸太大,则打印错误


在上传完成之前,您无法检查大小。

如果客户端没有可以看到文件系统的东西(如Java小程序),您无法提前知道它

你能做的最好的事情就是在上传文件之后,但在你做任何重要的事情之前,用它检查文件

list($width, $height) = getimagesize($_FILES['myfile']['tmp_name']); 

不幸的是,您只能在上载后使用检查维度

list($imagewidth, $width) = getimagesize("$myupload"); 

在php中,您可以在上载文件时获取文件维度。

您可能需要使用:

  • AS(动作脚本)(又名Flash)
  • Javascript
。。。在上传之前检查尺寸


始终考虑前端的方式,PHP应与客户端工具/语言/应用程序相结合,以提高效率。;)

不是真的与CakePHPwhy不相关,我在cakephp应用程序中这样做。。。。
$maxWidth = 40; // Setted 40px
$maxHeight = 40; // Setted 40px
list($width, $height) = getimagesize($_FILES['uploaded']['tmp_name']);

if ($width > $maxWidth || $height > $maxHeight) {
// Cancel upload
}