有人可以告诉我为什么我的脚本不会上传图片文件。另外,文件大小是否有一些限制?
基本上它应该工作的方式是每次上传图像时脚本应该更改最大尺寸,问题是当我尝试上传任何图像时if语句似乎失败并且它只是跳到其他地方。
第一部分是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>
答案 0 :(得分:1)
您应该验证所使用的相对文件路径是否指向正确的目标位置,并验证运行此脚本的用户是否具有对该目录的适当写入权限。