![]() |
|
|
|||||||
![]() |
|
|
Thread Tools | Rate Thread |
|
|
PM User | #1 |
|
Supreme Master coder! ![]() ![]() Join Date: Dec 2004
Location: In a place far, far away...
Posts: 17,411
Thanks: 2
Thanked 761 Times in 742 Posts
![]() ![]() ![]() ![]() ![]() |
PHP File Upload that sends email to person of choice depending on upload directory.
I recently code this for a user on the forums. Basically its a file upload script that will email a person depending on which directory was chosen. I think I've put in sufficient error checking. Once the file is uploaded successfully it redirects the user to a page and outputs that the file was uploaded to so and so directory. If any one sees any problems with it let me know please. One thing you should know if you use this script is that you should NOT allow it to be viewable to the public because you server could be filled up with junk. This should be used in a members only type area on your site. With that said here is the code. I commented it pretty well so it should be easy to follow. The directories you are uploading to must be chmodded to 777 for this script to work properly.
uploader.php PHP Code:
PHP Code:
__________________
||||If you are getting paid to do a job, don't ask for help on it!||||
|
|
|
|
|
|
PM User | #2 |
|
Senior Coder ![]() Join Date: Aug 2004
Location: Twin Cities
Posts: 1,345
Thanks: 0
Thanked 0 Times in 0 Posts
![]() |
I do not recommend the usage of empty() since it allows some ambiguity, if you want to look for an empty string, actually check for it $str=="" (someone could send in an array for $whereto which I believe would allow someone to see errors on the page which could reveal limited information about the server/file/error/blah).
also, your $whereto does not appear to be properly sanitized which may not make a difference but someone could do some http splitting when you do header(...). (note: I haven't had the chance to test these but.. yeah). |
|
|
|
|
|
PM User | #4 | |
|
Senior Coder ![]() Join Date: Aug 2004
Location: Twin Cities
Posts: 1,345
Thanks: 0
Thanked 0 Times in 0 Posts
![]() |
Quote:
I'd say its preferable to be paranoid all the time.. although I would say it is about being 'security conscious' .. |
|
|
|
|
|
|
PM User | #5 |
|
Regular Coder ![]() Join Date: Nov 2005
Posts: 951
Thanks: 1
Thanked 31 Times in 29 Posts
![]() |
You use basename but then don't include any restriction on $_POST['where']? So if $_POST['where'] == '/etc' and $_FILES[]['name'] == 'passwd', unless I'm missing something, you better hope all your permissions are secure?
OTOH, is_uploaded_file is implied by move_uploaded_file, so don't worry about that. I just don't think there's any easy way to sanitize a user supplied directory, I'd rather drop it all in ./upload/ or something and know the area of effect is restricted. Also, is this arbitrary file upload ending up somewhere inside document root? So I can upload blah.php == <?php eval($_GET['f']); ?>? If so it can be used to get a remote shell as apache's user and probably to elevate to root by a determined hacker. |
|
|
|
|
|
PM User | #6 | ||
|
Supreme Master coder! ![]() ![]() Join Date: Dec 2004
Location: In a place far, far away...
Posts: 17,411
Thanks: 2
Thanked 761 Times in 742 Posts
![]() ![]() ![]() ![]() ![]() |
Quote:
Quote:
So would this be okay in checking the upload directories? PHP Code:
__________________
||||If you are getting paid to do a job, don't ask for help on it!||||
Last edited by _Aerospace_Eng_; 04-28-2006 at 08:08 AM.. |
||
|
|
|
|
|
PM User | #7 |
|
Senior Coder ![]() Join Date: Aug 2004
Location: Twin Cities
Posts: 1,345
Thanks: 0
Thanked 0 Times in 0 Posts
![]() |
what ralph is getting is that someone can upload a PHP file which would be publically accessible.. which means you should be theoretically be checking against an allowed extensions array.
and.. a more aesthetically pleasing way to check for a valid directory would be to use an array of directories then using in_array() (fewer ||'s). |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Rate This Thread | |
|
|