Upload PHP Script Trouble

apps

#1

Trying to create a form to allow users to upload images. However, I get this error:

Warning: Unexpected character in input: ‘’ (ASCII=12) state=1 in /usr/local/dh/cgi-system/php.cgi on line 2987

Parse error: parse error, unexpected T_STRING in /usr/local/dh/cgi-system/php.cgi on line 2987

The form itself:

web.blazonry : PHP : Upload an Image <? if ($REQUEST_METHOD == "POST") { /* SUBMITTED INFORMATION - use what you need * temporary filename (pointer): $imgfile * original filename : $imgfile_name * size of uploaded file : $imgfile_size * mime-type of uploaded file : $imgfile_type */ /*== upload directory where the file will be stored relative to where script is run ==*/ $uploaddir = "/images"; /*== get file extension (fn at bottom of script) ==*/ /*== checks to see if image file, if not do not allow upload ==*/ $pext = getFileExtension($imgfile_name); $pext = strtolower($pext); if (($pext != "jpg") && ($pext != "jpeg")) { print "

ERROR

Image Extension Unknown. "; print "

Please upload only a JPEG image with the extension .jpg or .jpeg ONLY "; print "The file you uploaded had the following extension: $pext

\n"; /*== delete uploaded file ==*/ unlink($imgfile); exit(); } /*== setup final file location and name ==*/ /*== change spaces to underscores in filename ==*/ $final_filename = str_replace(" ", "_", $imgfile_name); $newfile = $uploaddir . "/$final_filename"; /*== do extra security check to prevent malicious abuse==*/ if (is_uploaded_file($imgfile)) { /*== move file to proper directory ==*/ if (!copy($imgfile,"$newfile")) { /*== if an error occurs the file could not be written, read or possibly does not exist ==*/ print "Error Uploading File."; exit(); } } /*== delete the temporary uploaded file ==*/ unlink($imgfile); print(""); /*== DO WHATEVER ELSE YOU WANT SUCH AS INSERT DATA INTO A DATABASE ==*/ } ?>

Upload and Resize an Image

Upload Image:

Click browse to upload a local file

<? /*== FUNCTIONS ==*/ function getFileExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } ?>

#2

you might want to change php to not run as cgi

look at this post
http://discussion.dreamhost.com/showflat.pl?Cat=&Board=forum_troubleshooting&Number=14226&page=0&view=collapsed&sb=5&o=14


#3

Thank you, that did it.

(I gave this a try:

$_SERVER[‘SCRIPT_FILENAME’] = $_SERVER[‘DOCUMENT_ROOT’].$_SERVER[‘SCRIPT_URL’];
$_SERVER[‘SCRIPT_NAME’] = $_SERVER[‘SCRIPT_URL’];

But, no cigar.)