PDA

View Full Version : Upload Script


gmonkey
03-14-2004, 02:53 PM
Hi

I have found a really simple upload script on this forum to my relief, (thanks to who wrote it), here it is below:



<form enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="2048000">
File: <input name="userfile" type="file" /><br />
<input type="submit" value="Upload" />
</form>

<?php
if (@is_uploaded_file($_FILES["userfile"]["tmp_name"])) {
copy($_FILES["userfile"]["tmp_name"], "image/" . $_FILES["userfile"]["name"]);
echo "<p>File uploaded successfully.</p>";
}

?>





I am trying to edit to so that it checks if the filename is equal to the variable $di which is picked up from the form on the previous page.

So something like
if userfile == $id.jpg then upload else
rename username to $id.jpg then upload

I am used to working with variables in scripts (im a newbie) so dont know how to assign the username to do a check?

Any ideas?

knigh7
03-23-2004, 09:29 AM
hello;
thank you thank you thank you......

cool script.....

regards,
ahmad

MikeParent
03-23-2004, 11:23 AM
Not sure why you would care what the name of the uploaded file is? If you need it to be named something specific you could just rename it when you copied it to the destination folder instead...

PS: You are allowing 2 MB image upload?! That is mighty big

gmonkey
03-23-2004, 12:15 PM
Originally posted by knigh7
hello;
thank you thank you thank you......

cool script.....

regards,
ahmad

Its such a cool lil gem, considering there are LENGTHY tutorials around, this one does it , simple and effectively, allowing u to add any constraints you want :-)

azlatin2000
03-23-2004, 12:35 PM
Originally posted by MikeParent
PS: You are allowing 2 MB image upload?! That is mighty big

Another problem with the script is you could just change the value from 2 megs to 99999999999999 megs or whatever the limit is in php.ini and then use it to host your images that you don't have space for on your host

gmonkey
03-23-2004, 02:51 PM
It seems to work fine for me, its only for internal use, and the file limit is set to 20kb after editing, and the host has unlimited web space if thats what you mean?

Thank you to the guy that created the script :-)