【发布时间】:2012-05-13 18:47:36
【问题描述】:
我想在通过 Javascript 上传 PHP 中的图像之前验证图像分辨率。在我的 php 表单中,我想上传两个不同的图像,并且两个图像都有不同的分辨率限制。
我试试下面的代码
PHP 代码
echo "<form name='add' enctype='multipart/form-data' action='AppActions.php' method='post' onSubmit='return validate_create();'>";
echo "<div class='form_label'>Album Wrapper (Big Image) *</div>";
echo "<div class='form_input'><input type='file' name='bigimage' id='bigimage' />";
echo "<div class='form_label'>Album Wrapper (Small Image) *</div>";
echo "<div class='form_input'><input type='file' name='smallimage' id='smallimage' />;
echo "<input type='submit' name='add' value='Create' class='Buttons' id='add'>";
在 Javascript 中
function validate_create()
{
var bigimage = document.getElementById('bigimage');
var smallimage = document.getElementById('smallimage');
var big_img_width = bigimage.clientWidth;
var big_img_height = bigimage.clientHeight;
var small_img_width = smallimage.clientWidth;
var small_img_height = smallimage.clientHeight;
// if condtion to check the condition //
}
在这里,即使我选择不同大小的文件,我也会得到相同的两个图像的宽度和高度。
如何做到这一点?请给我建议
提前致谢
【问题讨论】:
-
在上传到服务器之前,您可以在 PHP 中检查,但不能在 javascript 中检查
-
感谢 user1331534。在上传之前如何使用 PHP 进行检查?你能帮我解决这个问题吗?
-
在用户上传文件之前 无法使用 PHP。
标签: php javascript validation resolution image-size