有人可以告诉我为什么我的脚本不会上传图像文件。此外,是否对文件的大小设置了一些限制?
基本上它应该工作的方式是每次上传图像时脚本都应该更改最大大小,问题是当我尝试上传任何图像时,if语句似乎失败并且它只是跳到else。
第一部分是php:
if (isset($_FILES['image']['name'])) {
$title = sanitizeString($_POST['title']);
$title = nl2br($title);
$saveto = str_replace(" ", "", $title);
$saveto = str_replace("'", "", $saveto);
$saveto = "blogImages/$saveto.jpg";
if (move_uploaded_file($_FILES['image']['tmp_name'], $saveto)) {
echo "You Have Succesfully Uploaded an Image!";
$typeok = true;
switch($_FILES['image']['type'])
{
case "image/gif": $src = imagecreatefromgif($saveto); break;
case "image/jpeg": // Both regular and progressive jpegs
case "image/pjpeg": $src = imagecreatefromjpeg($saveto); break;
case "image/png": $src = imagecreatefrompng($saveto); break;
default: $typeok = FALSE; break;
}
if ($typeok)
{
list($w, $h) = getimagesize($saveto);
$max = 800;
$tw = $w;
$th = $h;
if ($w > $h && $max < $w)
{
$th = $max / $w * $h;
$tw = $max;
}
elseif ($h > $w && $max < $h)
{
$tw = $max / $h * $w;
$th = $max;
}
elseif ($max < $w)
{
$tw = $th = $max;
}
$tmp = imagecreatetruecolor($tw, $th);
imagecopyresampled($tmp, $src, 0, 0, 0, 0, $tw, $th, $w, $h);
imageconvolution($tmp, array(array(-1, -1, -1),
array(-1, 16, -1), array(-1, -1, -1)), 8, 0);
imagejpeg($tmp, $saveto);
imagedestroy($tmp);
imagedestroy($src);
}
} else {
echo "You have not uploaded an Image";
}
这是 HTML:
<body>
<form id = 'blogPostInput' method='post' action = 'inputBlog.php' enctype='multipart/form-data'>
<h3> Enter or Edit a Blog </h3>
<br/>
Blog Post Title:
<br/>
<input type='text' value='' name='title' maxlength='64'/>
<br/>
Enter an Image or Video URL
<br/>
<input type='text' value='' name='video' maxlength = '128'/>
<br/>
<input type='file' name='image' maxlength='150' />
Enter the Blog Post's Text
<br/>
<textarea name='blogPostContent' cols='100' rows='5'></textarea>
<br/>
<input type='hidden' id='timeStamp' name='timeStamp' maxlength = '64'/>
<br/>
<input type='submit' value= 'Save Blog Post'/>
</form>
</body>