【发布时间】:2014-10-05 00:11:16
【问题描述】:
我创建了一个简单的上传表单,所有代码都可以正常工作,但是当我上传 2kb、20kb、26kb 时,图片会上传,但是当我尝试上传 60kb、66kb 时,页面会卡在加载中, 我不知道为什么会这样,我还更改了 php.ini 中的 max-upload-size。 谁能告诉我为什么会这样?
Signup.php
<!DOCTYPE html>
<head>
<title>Index</title>
</head>
<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>
register.php
<?php
$target_dir = "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"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
这就是我的全部了,请检查一下...
注意告诉我一个解决方案,当我在window xp上测试上面的代码时,它会正常运行,我上传了103kb的文件,但它在window 8上不起作用,并创建我上面提到的问题... Xammp 最新版本是否有错误,或者是什么问题?
注意 错误不是代码,错误是合乎逻辑的,所以请具体点。 请添加解释性答案....
【问题讨论】:
-
如果用户使用您的上传器上传了
.php文件会怎样? -
我尝试了 try catch 块但没有显示错误,主要问题是我在上面的问题中讨论过。和 serakfalcon 我知道你的意思是扩展验证,我会在后面加上它,但现在我被困在上传中..
-
上传图片的分辨率是多少?您是否尝试过使用其他浏览器?
-
$image['name'] = $image['name'] 是什么意思???
-
分辨率不代表,$image['name']=$image['name']