限制输入框选项JS
Limit input field options JS
我在 Wordpress 网站上工作,我有一个非常简单的 <input type="image">
用户可以通过它发送图像文件。
我有一些非常具体的要求,我希望上传的文件是:
- 最小 3000x3000 像素
- 最大 5000x5000 像素
- 最大 36MB
- 1:1 纵横比
我可以通过 JS/jQuery 设置此限制吗?
要在上传前获取有关图片的信息,请使用 wp_handle_upload_prefilter
。纵横比是比较宽度和高度。
function test($file) {
$data = getimagesize($file['tmp_name']);
error_log(print_r($data,true));
//Returns
// Array (
// [0] => 3000 // width
// [1] => 3000 // height
// [2] => 3
// [3] => width="3000" height="30000"
// [bits] => 8
// [mime] => image/png
// )
error_log(print_r($file,true));
//returns
// Array (
// [name] => filename.png
// [type] => image/png
// [tmp_name] => /tmp/phpEJC5NR
// [error] => 0
// [size] => 4347 // file size in bits
// )
return $file;
}
add_action('wp_handle_upload_prefilter','test');
我在 Wordpress 网站上工作,我有一个非常简单的 <input type="image">
用户可以通过它发送图像文件。
我有一些非常具体的要求,我希望上传的文件是:
- 最小 3000x3000 像素
- 最大 5000x5000 像素
- 最大 36MB
- 1:1 纵横比
我可以通过 JS/jQuery 设置此限制吗?
要在上传前获取有关图片的信息,请使用 wp_handle_upload_prefilter
。纵横比是比较宽度和高度。
function test($file) {
$data = getimagesize($file['tmp_name']);
error_log(print_r($data,true));
//Returns
// Array (
// [0] => 3000 // width
// [1] => 3000 // height
// [2] => 3
// [3] => width="3000" height="30000"
// [bits] => 8
// [mime] => image/png
// )
error_log(print_r($file,true));
//returns
// Array (
// [name] => filename.png
// [type] => image/png
// [tmp_name] => /tmp/phpEJC5NR
// [error] => 0
// [size] => 4347 // file size in bits
// )
return $file;
}
add_action('wp_handle_upload_prefilter','test');