Forgive me if this answer is posted already somwhere, but i didn't know what to search for.
I am trying to make my own image uploader that will basically do exactly what imageshack.us does. It will upload the image, then make a thumbnail of it. but I am getting errors that don't seem to make much sense. here's my code (with the password part changed to keep my real password secret):
[php]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Image Uploader</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="form1" method="post" action="" enctype="multipart/form-data">
<input type="file" name="imagefile">
<br>
<input type="password" name="pass" value="password" >
<input type="submit" name="Submit" value="Submit">
<?php
if(isset( $Submit )) { //If the Submitbutton was pressed do:
if($pass != "pancakes"){ //check the password
echo "incorrect password";
} else {
if ($_FILES['imagefile']['type'] == "image/gif" or $_FILES['imagefile']['type'] == "image/jpeg" or $_FILES['imagefile']['type'] == "image/png"){
//check file type
copy ($_FILES['imagefile']['tmp_name'], "files/".$_FILES['imagefile']['name']) //save the image
or die ("Could not copy");
$file = $_FILES['imagefile']['name'];
echo "<br>";
echo "Name: ".$file."<br>";
echo "Size: ".round((($_FILES['imagefile']['size'])/1024),2)." kb<br>";
echo "Type: ".$_FILES['imagefile']['type']."<br>";
echo "Upload Complete...<br>";
echo "<a href=\"files/".$file."\"><img src=files/".$file."></a><br>";
echo "inline image: <input name=\"bb\" type=\"text\" id=\"bb\" value=\"
\" size=\"50\"><br>";
echo "link to image: <input name=\"bb2\" type=\"text\" id=\"bb2\" value=\"
Click here!\" size=\"50\">";
##############################
//start thumbnail creator here:
$filename = "files/".$file;
// Set a maximum height and width
$width = 200;
$height = 200;
## // Content type
## header('Content-type: image/jpeg');
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);
if ($width && ($width_orig < $height_orig)) {
$width = ($height / $height_orig) * $width_orig;
} else {
$height = ($width / $width_orig) * $height_orig;
}
// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Output
imagejpeg($image_p, substr($filename,0,(strlen($filename-4))."tn.jpg", 90);
}
else {
echo "<br><br>";
echo "Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")<br>";
echo $_FILES['imagefile']['type'];
}
}
}
?> </form>
</body>
</html>
[/php]
with this code I get the following error:
Parse error: parse error, unexpected ';' in /path/to/page.php on line 63
if I comment out this line:
imagejpeg($image_p, substr($filename,0,(strlen($filename-4))."tn.jpg", 90);
it loads correctly, but doesn't make the thumbnail obviously.
I tried simply removing the ";" at the end of the line (I know that doesn't make sense but it was worth a try), and that only resulted in more errors.
ANyone have any suggestions? This is probably something really obvious, but I'm just overlooking it. Thanks in advance.