file uploading code

A

Anonymous

Guest
Hi guys,

can somebody give me an idea what have i done wrong ??? it displayed "Error : Possible file upload error" as my output..

my code:
<head>
<title>
Uploading ....
</title>
</head>

<body>
<h1> Uploading file .. </h1>
<?
if($userfile == "none")
{
echo 'Error : No file uploaded ';
exit;

}

if($usefile_size == 0)
{
echo 'Error : Uploaded file is zero lenght';
exit;
}

if($usefile_type != "image/gif")
{
echo 'Error : Incompatible file detected';
exit;
}

if(!is_uploaded_file($userfile))
{
echo 'Error : Possible file upload error';
exit;
}

$upfile = $userfile_name;

if(!copy($userfile, $upfile))
{
echo 'Error : Could not copy the file';
exit;
}


echo "File uploaded <br><br>";

$fp = fopen($upfile,"r");
$content = fread($fp, filesize ($upfile));
fclose($fp);

$contents = strip_tags($contents);
$fp = fopen($upfile, "w");
fwrite($fp, $contents);
fclose($fp);

echo "preview of uploaded file contents: <br><hr>";
echo $contents;
echo "<br><hr>";
?>
</body>


everything looks okay for me but why i still get this error when i upload gif file.. i have changed to text/plain and upload text file but error still occured (display "Error:Incompatible file detected") My code just doesn't work at all...

is there any website i can go to refer to what i suppose to use when i wanna upload a word doc, excel file and etc .. (i mean like image/jpeg , text/,,,, )

hope you guys may able to help me.

please advise.
 
register_globals is off or on ?
$_FILES['']

- refer to manual
http://www.google.com/search?sourceid=navclient&q=tutorial+file+uploading+php
 
I see a little error in this piece of code:

Code:
if($usefile_type != "image/gif") 
{ 
echo 'Error : Incompatible file detected'; 
exit; 
}

$usefile_type => $userfile_type right?
 
There are a couple of $usefile typo's in there. Also, a
$content = fread($fp, filesize ($upfile));

Should be $contents (with an "s"), yeah?

Scrub that code and compare your variables.
 
Back
Top