PHP File Uploading Scripts

um, yeah.

ok, i’m an aspiring coder (read: some lazy guy who has a cheap webserver at home and doesn’t like to carry floppy disks to school :p), and i was looking around for some beginner level PHP scripts that would let me upload files through the HTTP protocal (err, that’s redundant, isn’t it…) to my server, from school.

i’ve seen several ones built into forums (like the one right here), but i don’t want to make a forum just to use the upload script :D. so, i was wondering if there are any standalone scripts that someone could point me too. doesn’t need to do much, just let me upload files to one folder and then i’ll be happy. if possible, i’d want password protection, but that’s not the biggest deal to me.

so, if anyone knows where to get any good scripts that work, please tell me, cause i don’t like floppy disks… :slight_smile:

and thanks in advance to anyone who can help.

i can pull out all the ‘forum’ stuff from the image gallery, and post it on here.

it used to be stand-a-lone

It will just have the input box for the filename and then save it somewhere on your servers filesystem.

I’ll put the script up tonight.

hmm, i guess i could try that. as i said before, it just needs to be able to handle any type of file uploads. of course, i’d rather be able to block other scripts or exe’s, or have password protection, but i’m sure i can find a way around that.

one other question. if i took a PHP script that offered password protection, and then put that to login to the file uplaod thing, would that work? i’m not really good with PHP, so i don’t really know what i’m talking about :p. just a random idea that poped into my head. the only other idea i have for password protection is some crazy way through IIS (or apache, if i’m ever not lazy enough to go and make it work), because i think it’s possible to do that, but once again, i’m not really sure.

anyways, thanks again brandon. :smiley:

it depends on what kind of security script you have.

the easiest way to do it (if you can & know how) is to set up .htaccess on apache.

If you’re going to only have one login, then we can do a real simple username/password thing with the script.

I will make it so it only accepts file extensions that you specify. And has one login.

…or if you wanna take the cheap-n-easy dan way out…

dump this into a file and name it upload.html:


 <html><head><title>PHP's FileUPLOAD</title></head><body>
<form enctype="multipart/form-data" action="upload.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="500000">
Username: <input type="text" name="user" size="10"> <br>
Password: <input type="password" name="pw" size="10"><br>
Send this file: <input name="userfile" type="file">
<input type="submit" value="Send File">
</form>
</body>
</html>

and name this upload.php


<?php 
if ($user != "ian"  ||  $pw != "is_hot")
    exit();

// In PHP earlier then 4.1.0, $HTTP_POST_FILES  should be used instead of $_FILES.
if (is_uploaded_file($_FILES'userfile']'tmp_name'])) {
    copy($_FILES'userfile']'tmp_name'], "uploads/".$_FILES'userfile']'name']);
    echo "upload success!";
} else {
    echo "Possible file upload attack. Filename: " . $_FILES'userfile']'name']
    ."<br>(<a href=\"http://www.php.net/manual/en/features.file-upload.errors.php\">error code</a> ". $_FILES'userfile']'error'] .")";
}
?>

That basically uploads the file to a directory called “uploads” in the php script directory (you have to make it) when the username is “ian” and the pw is “is_hot”. This is quick, dirty, but it should work (if you have the newer php version and didn’t set a crazy anti-global directive thing in the php config file, you need to change the first php line to:
if ($_POST’user’] != “ian” || $_POST’pw’] != “smells”)
for more info, go here and here

yeah
thats basically what i was gonna do.

dan saved me some time.

mines a bit more cumbersome and probably confusing…

almost like HTML but different.

well, the top is html . … :slight_smile:

dan’s thing works, but i have some problems with certain files. not a huge thing, just kinda annoying. now, i should probably learn PHP… :stuck_out_tongue:

EDIT

yeah, i think the problem is with having the file size too small, but i made it much bigger (like, a GB), and it still failed to load a 2 MB file. i’m not sure if it’s because it was an exe too, but it gave me errors based on file size. any ideas?

Perl rules! Woo! kicks php :slight_smile:

*Originally posted by Ian W. *
** but it gave me errors based on file size. any ideas? **

what were the errors?
copy/paste em, and we can help better

before it gave me error codes 1 and 2 for uploading files, now it just displays a blank screen and does nothing. i’m not sure why. maybe you guys have an idea?

Probably cause the username/password don’t match and it was a 5-minute coding job so there’s nothing in the code to tell you that, so nothing happens. Try changing the first few lines of the PHP to this:


if ($user != "ian"  ||  $pw != "is_hot") {
   echo "Username and Password don't match.  Hit back and try again.";
   exit();
}

*Originally posted by Ian W. *
**before it gave me error codes 1 and 2 for uploading files, now it just displays a blank screen and does nothing. i’m not sure why. maybe you guys have an idea? **

if you are still having problems try checking your php.ini file and the max file size argument. The max file size thing in the input is just an advisement, while the one in the php.ini file is the law, it can’t be bigger than that, no matter what.

p.s. thanks to the people that posted this script, i wanted to do the same thing, and it was really easy to intregrate into my current user/login system :slight_smile: thanks

where is the php.ini file? :stuck_out_tongue: i saw it mentioned, but i couldn’t find it anywhere.

well, on my windows 98 setup i put it in the windows directory. c:\windows\ but it would be c:\winnt\ for a nt\2k configuration. try searching your hd for it