Forum Moderators: coopster
I found lotta stuff, but they were for only gif or only jpeg upload, i would like to be able to upload at least both types.
I found this code below somewhere on www, but i can't get it to work.
I 777'd the upl directory. I select a file, click upload, but i always get the error message.
What is wrong? (or maybe there is a specific thread i should read,please point me to it. thanks.)
-----
uploadform.php:
<form enctype="multipart/form-data" action="upload.php" method="post" name="upload_file">
<input type="hidden" name="MAX_FILE_SIZE" value="5000000">
<input name="userfile" type="file">
<input type="submit" value="upload" name="file_uploaded">
</form>
-----
upload.php:
if (is_uploaded_file($_FILES['userfile']['tmp_name']))
{
$file_realname = $_FILES['userfile']['name'];
copy($_FILES['userfile']['tmp_name'], "http://www.the-server.nl/upl/".trim($file_realname));
}
else
{
echo "<b><font color=red>No file uploaded.</font></b><BR>No file available or file too big to upload.";
}
echo $file_realname;
?>
$file_realname = trim($_FILES['userfile']['name']);
$uploaddir = your/dir/;
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir . $file_realname)) {
} else {
print "<strong>$file_realname</strong> did not upload!";
}
added semicolon
[edited by: Birdman at 1:24 pm (utc) on Mar. 1, 2003]
$file_realname = test.jpg;
Or echo the variable:
$file_realname = trim($_FILES['userfile']['name']);
echo $file_realname;
Not sure if you have already tried this.
<sorry>After re-reading your post, I see that the var was not set. Maybe try removing trim().
Found it here [php.net].
$file_realname = trim($HTTP_POST_FILES['userfile']['name']);
edit reason-typo-just woke up ;)
The filename now shows up, but no upload.
The code is now:
$file_realname = trim($HTTP_POST_FILES['userfile']['name']);
$uploaddir = "upl/";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir . $file_realname)) {
} else {
print "<strong>$file_realname</strong> did not upload!";
}
echo $file_realname;
I will study the link. And start from scratch.
Too bad, that i can't even get the a ready-made php example to work.