javascript - 如何以像素为单位获取上传图像分辨率? (上传前)

标签 javascript php html ajax image-upload

上传前如何获得以像素为单位的图像分辨率?有什么解决方案可以按我的意愿制作吗?没有改变这段代码的大变化?请! 代码只限制文件大小。但我需要以像素为单位限制文件大小和分辨率!

对不起!我的英语知识太差了。我希望你能理解这一点。谢谢!

 <?php
if (isset($_POST['submit'])) {
    $j = 0; //Variable for indexing uploaded image 

    $target_path = "uploads/"; //Declaring Path for uploaded images
    for ($i = 0; $i < count($_FILES['file']['name']); $i++) {//loop to get individual element from the array

        $validextensions = array("jpeg", "jpg", "png", "gif");  //Extensions which are allowed
        $ext = explode('.', basename($_FILES['file']['name'][$i]));//explode file name from dot(.) 
        $file_extension = end($ext); //store extensions in the variable

        $target_path = $target_path . md5(uniqid()) . "." . $ext[count($ext) - 1];//set the target path with a new name of image
        $j = $j + 1;//increment the number of uploaded images according to the files in array       

      if (($_FILES["file"]["size"][$i] < 500000) //Approx. 500kb files can be uploaded.
                && in_array($file_extension, $validextensions)) {
            if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path)) {//if file moved to uploads folder
                echo $j. ').<span id="noerror">Image uploaded successfully!.</span><br/><br/>';
            } else {//if file was not moved.
                echo $j. ').<span id="error">please try again!.</span><br/><br/>';
            }
        } else {//if file size and file type was incorrect.
            echo $j. ').<span id="error">***Invalid file Size or Type***</span><br/><br/>';
        }
    }
}
?>

最佳答案

使用getimagesize function :

list($width, $height, $type, $attr) = getimagesize($_FILES['file']);

现在您可以访问图像的 $width$height

关于javascript - 如何以像素为单位获取上传图像分辨率? (上传前),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26891234/

相关文章:

php - HREF 向 Controller 发送参数并返回 View

php - laravel mysql 显示表

php - 使用php强制下载pdf

php - 为 Mysql 层表生成 JSON 对象 (PHP)

javascript - Codecademy 练习 : portfolio

javascript - 在谷歌地图上添加多个标记

javascript - JQuery "click"未触发函数

javascript - 在 KineticJS 中使用 mousedown 事件创建一个矩形

javascript - 将 Selenium-IDE 源代码导出为 JavaScript 代码

javascript - 从 HTML5 存储打开 PDF