Can someone tell me why my script won't upload image files. Additionally, is there some limitation set on the size of the file?
Basically the way it should work is that every time an image is uploaded the script should change the maximum size, the problem is that when I try to upload any image the if statement seems to fail and it just skips to the else.
The first part is the 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";
}
This is the 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>