【发布时间】:2014-11-26 07:26:08
【问题描述】:
我想在我的网站上实现多个部分,访问者可以在其中上传要显示的图像。 我让它在服务器上的一个测试文件夹中完美地工作,它回显“文件是一个图像。[文件]成功上传”并且图像出现在服务器上。
但是,在网站中实际执行此脚本(我将脚本复制到不同的文件夹),我得到返回:500 Internal Server error。
你们中有人知道是什么导致了这个问题吗?
HTML 表单(在 /entries.php 中):
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="../../style.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#000000">
<form action="upload.php" method="post" enctype="multipart/form-data"><p class="text">
Upload your entry here!:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit"></p>
</form>
</body>
</html>
PHP 脚本(在 upload.php 中):
<?php
$target_dir = "images/";
$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.";
}
}
?>
【问题讨论】:
-
检查你的网络服务器(可能是 apache2)的日志文件,它会告诉你 500 内部错误是什么
-
感谢您的回复。可悲的是,我的网络服务器由 GoDaddy 托管。我可以看到谁在连接哪个页面的日志文件,但没有错误日志。