gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 10:10:39 24 4
gpt4 key购买 nike

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

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

 <?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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com