/    Sign up×
Community /Pin to ProfileBookmark

upload file prob

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.

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@chris9902Dec 15.2003 — to upload files try this,

from Robouk ( i take NO credit for this )


Many times, a programmer will want to let the user upload a file to the server, like on deviantart.com when they submit there work. This quick tutorial will show you how to upload a file using php.

First we want an html page that lets the user select the file from there computer.

<!doctype html public "-//W3C//DTD HTML 4.0 //EN">

<html>

<head>

<title>Title here!</title>

</head>

<body>

<form action="upload.php" method="post" enctype="multipart/form-data">

<input type="hidden" name="MAX_FILE_SIZE" value="1000000">

Select a file to upload! <input type="file" name="userfile"><br>

<input type="submit" value="Upload!">

</form>

</body>

</html>

Save that file as upload.htm Notice the MAX_FILE_SIZE hidden input. We set that number in bytes, as the largest file that can be uploaded. In this case it is one megabtye. Now we want to create the upload.php file that will actually upload the file.

<?php

if(!(copy($_FILES['userfile']['tmp_name'], "Upload/" . $_FILES['userfile']['name']))) die("Cannot upload files.");

echo "Upload Complete!";

?>

Less complicated then you thought huh ? This will only work in version 4.2.0 or greater. If you are running an older veresion replace $_FILES with $HTTP_POST_FILES When we upload the file it is just a copy. Copy The user file with the name it has on the users computer to the direcrtory Upload/ and call the file it's name. If the upload doesn't work, it dies, else the user sees upload complete. Now go forth and upload!

[/QUOTE]
Copy linkTweet thisAlerts:
@chris9902Dec 15.2003 — just when you think you helped someone Pyro comes along and makes you look like a fool:p

nice script?
Copy linkTweet thisAlerts:
@pyroDec 15.2003 — Not trying to step on any toes, just trying to help out... ? :p
Copy linkTweet thisAlerts:
@chris9902Dec 15.2003 — [size=1]*walking off crying*[/size] you won this battle...

Anyway... they both work and there both good?
×

Success!

Help @Alicia spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...