在获得用户上传到服务器的图像大小之前,我还有一个用PHP编写的不完整代码。
HTML表单代码:
<!DOCTYPE html>
<html>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
</body>
</html>
<?php
$target_dir = "C:/xampp/htdocs/php_playground/uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
echo "Check Value with tmp_name parameter : \n";
echo "<pre>";
print_r($check);
echo "</pre>";
die;
}
?>
PHP代码1的输出如下:
Check Value with tmp_name parameter :
Array
(
[0] => 1536
[1] => 2048
[2] => 2
[3] => width="1536" height="2048"
[bits] => 8
[channels] => 3
[mime] => image/jpeg
)
PHP代码2:
<?php
$target_dir = "C:/xampp/htdocs/php_playground/uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["name"]);
echo "Check Value with name parameter : \n";
echo "<pre>";
print_r($check);
echo "</pre>";
die;
}
?>
PHP代码2的输出如下:
:getimagesize(demo\u image.jpg):无法打开流:中没有此类文件或目录
C: \xampp\htdocs\php\u playfield\uploads\upload。php
8.
使用名称参数检查值:
getimagesize()
$_FILES
大堆
请在这方面指导我。