| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | #2 (permalink) |
| New Member Join Date: Nov 2005
Posts: 4
![]() | Heres one i found off google: <?php //vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv vvvvvvvvvv // You may change maxsize, and allowable upload file types. //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ //Mmaximum file size. You may increase or decrease. $MAX_SIZE = 200000000000; //Allowable file Mime Types. Add more mime types if you want $FILE_MIMES = array('application/pdf','video/mpg','video/avi','image/jpeg','image/jpg','image/gif' ,'image/png','application/msword'); //Allowable file ext. names. you may add more extension names. $FILE_EXTS = array('.pdf','.txt','.zip','.jpg','.png','.gif','. avi','.mpg','.mpeg','.asf'); //Allow file delete? no, if only allow upload only $DELETABLE = false; //vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv vvvvvvvvvv // Do not touch the below if you are not confident. //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ /************************************************** ********** * Setup variables ************************************************** **********/ $site_name = $_SERVER['HTTP_HOST']; $url_dir = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['php_SELF']); $url_this = "http://".$_SERVER['HTTP_HOST'].$_SERVER['php_SELF']; $upload_dir = "files/"; $upload_url = $url_dir."/files/"; $message =""; /************************************************** ********** * Create upload Directory ************************************************** **********/ if (!is_dir("files")) { if (!mkdir($upload_dir)) die ("upload_files directory doesn't exist and creation failed"); if (!chmod($upload_dir,0755)) die ("change permission to 755 failed."); } /************************************************** ********** * Process User's Request ************************************************** **********/ ????: NamePros.com http://www.namepros.com/programming/141530-php-upload-script.html if ($_REQUEST[del] && $DELETABLE) { $resource = fopen("log.txt","a"); fwrite($resource,date("Ymd h:i:s")."DELETE - $_SERVER[REMOTE_ADDR]"."$_REQUEST[del]\n"); fclose($resource); if (strpos($_REQUEST[del],"/.")>0); //possible hacking else if (strpos($_REQUEST[del],$upload_dir) === false); //possible hacking else if (substr($_REQUEST[del],0,6)==$upload_dir) { unlink($_REQUEST[del]); ????: NamePros.com http://www.namepros.com/showthread.php?t=141530 print "<script>window.location.href='$url_this?message=d eleted successfully'</script>"; } } else if ($_FILES['userfile']) { $resource = fopen("log.txt","a"); fwrite($resource,date("Ymd h:i:s")."upload - $_SERVER[REMOTE_ADDR]" .$_FILES['userfile']['name']." " .$_FILES['userfile']['type']."\n"); fclose($resource); $file_type = $_FILES['userfile']['type']; $file_name = $_FILES['userfile']['name']; $file_ext = strtolower(substr($file_name,strrpos($file_name,". "))); //File Size Check if ( $_FILES['userfile']['size'] > $MAX_SIZE) $message = "The file size is over 2MB."; //File Type/Extension Check else if (!in_array($file_type, $FILE_MIMES) &&!in_array($file_ext, $FILE_EXTS) ) $message = "Sorry, $file_name($file_type) is not allowed to be uploaded."; else $message = do_upload($upload_dir, $upload_url); print "<script>window.location.href='$url_this?message=$ message'</script>"; } else if (!$_FILES['userfile']); else $message = "Invalid File Specified."; /************************************************** ********** * List Files ************************************************** **********/ $handle=opendir($upload_dir); $filelist = ""; while ($file = readdir($handle)) { if(!is_dir($file) &&!is_link($file)) { $filelist .= "<a href='$upload_dir$file'>".$file."</a>"; if ($DELETABLE) { $delfile = $file; $delfile = str_replace("%","%25",$delfile); $delfile = str_replace("&","%26",$delfile); $delfile = str_replace("+","%2b",$delfile); $delfile = str_replace("?","%3f",$delfile); $filelist .= " <a href='?del=$upload_dir".$delfile."' title='delete'>x</a>"; } $filelist .= "<sub><small><small><font color=grey> ".date("d-m H:i", filemtime($upload_dir.$file)) ."</font></small></small></sub>"; $filelist .="<br>"; } } function do_upload($upload_dir, $upload_url) { $temp_name = $_FILES['userfile']['tmp_name']; $file_name = $_FILES['userfile']['name']; $file_name = str_replace("\\","",$file_name); $file_name = str_replace("'","",$file_name); $file_path = $upload_dir.$file_name; //File Name Check if ( $file_name =="") { $message = "Invalid File Name Specified"; return $message; } $result = move_uploaded_file($temp_name, $file_path); if (!chmod($file_path,0777)) $message = "change permission to 777 failed."; else $message = ($result)?"$file_name uploaded successfully." : "Somthing is wrong with uploading a file."; return $message; } ?> <center> <font color=red><?=$_REQUEST[message]?></font> <br> <form name="upload" id="upload" ENCTYPE="multipart/form-data" method="post"> upload File <input type="file" id="userfile" name="userfile"> <input type="submit" name="upload" value="upload"> </form> <br><b>upload area</b> <hr width=70%> <?=$filelist?> <hr width=70%> <small><sup>Maintained by "Me" <a style="text-decoration:none" href="http://URL-HERE/forum">Back</a> </sup></small> </center> |
| |
| | #4 (permalink) |
| Senior Member Join Date: Mar 2005
Posts: 4,948
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Here is something simple: PHP Code: |
| |
| | THREAD STARTER #5 (permalink) | ||||
| Account Closed Join Date: Oct 2005 Location: United Kingdom
Posts: 1,554
![]() ![]() ![]() ![]() | dose not work
| ||||
| |
| | #6 (permalink) |
| Eating Pie Join Date: Nov 2004 Location: Canada
Posts: 2,272
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Try this.. PHP Code: iNod.
__________________ I feel old. |
| |
| | #7 (permalink) | ||||
| NamePros Regular Join Date: Jun 2005 Location: Indiana, USA
Posts: 391
![]() ![]() ![]() |
And for once I found one that actually does work for me! Now maybe I can actually develop image-host.be lol!BTW, Inod, is there anyway to get the image to pop up in a new window when you click on the link? I tried adding "target="_blank"" to it but it gave me some error. ![]() EDIT: Never mind, I got it!
Last edited by AJ; 11-22-2005 at 03:41 AM.
| ||||
| |
| | #8 (permalink) |
| Senior Member Join Date: Oct 2005 Location: Kent ~ U.K.
Posts: 3,209
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | wow, its a nice script! iNod continues to impress us all!... again!
__________________ Myself and "JackHeskett" are no longer associated with FusedHosting.net. Please pipe all PMs to admin [at] fusedhosting.net. |
| |
| | #10 (permalink) |
| NamePros Member Join Date: Nov 2005 Location: the Netherlands
Posts: 127
![]() | I wrote a very detailed tutorial on this once. It's at: http://minnwyb.beigetower.org/posts/web-upload-script/
__________________ accepts paypal and cookies |
| |
| | #11 (permalink) |
| NamePros Member Join Date: Oct 2005
Posts: 173
![]() | Is there any way to get around the php setting that doesn't allow uploads over a certain size to be done... or the max execution time? I would like to be able to have files uploaded that are up to 5MB and I have encountered the above problems. |
| |
| | #12 (permalink) |
| Senior Member Join Date: Mar 2005
Posts: 4,948
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | You could always... PHP Code: http://us2.php.net/manual/en/ini.php#ini.list More info on ini_set: http://us2.php.net/ini_set |
| |
| | #14 (permalink) |
| NamePros Member Join Date: Oct 2005
Posts: 173
![]() | Wow, thanks a ton. That helped a lot. So then it appears as though the values are only for the script that is doing the uploading at the time? So that i don't have to set it back to what it was once the script is done executing? |
| |
| | #15 (permalink) |
| Eating Pie Join Date: Nov 2004 Location: Canada
Posts: 2,272
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | int_set function sets a variable for Apache for just this excution. It will revert back to the normal settings in php.ini after processing. If you have safe_mode on for php than it may cause some problems or errors. if you experience this ask your host to change save_mode to off. iNod.
__________________ I feel old. |
| |
| | THREAD STARTER #17 (permalink) | ||||
| Account Closed Join Date: Oct 2005 Location: United Kingdom
Posts: 1,554
![]() ![]() ![]() ![]() |
| ||||
| |
| | #18 (permalink) | ||||
| Senior Member Join Date: Mar 2005
Posts: 4,948
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
????: NamePros.com http://www.namepros.com/showthread.php?t=141530 Anyway, you could do something like this: PHP Code: | ||||
| |
| | #19 (permalink) |
| NamePros Member Join Date: Aug 2005
Posts: 145
![]() | Great code. One question for you. How can I limit what files can be chosen throught the dialog box when choosing a file (ie. 'mpg', 'mp3'). I know it currently will show an error after trying to upload an extension that isn't allowed, but how do I limit the dialog box. Thanks |
| |
| | #20 (permalink) | ||||
| Eating Pie Join Date: Nov 2004 Location: Canada
Posts: 2,272
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
????: NamePros.com http://www.namepros.com/showthread.php?t=141530 PHP doesn't have a way to do this sorry. iNod
__________________ I feel old. | ||||
| |
| | #21 (permalink) |
| Senior Member Join Date: Oct 2005 Location: Kent ~ U.K.
Posts: 3,209
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | i have another question that i hope you can help with...does php have a script that will record the ip address and file name when an image is uploaded? in a seperate file e.g. text.jpg ¦ 111.111.111.111 i hope it can be done
__________________ Myself and "JackHeskett" are no longer associated with FusedHosting.net. Please pipe all PMs to admin [at] fusedhosting.net. |
| |
| | #22 (permalink) |
| NamePros Regular Join Date: May 2005 Location: Oklahoma City Oklahoma
Posts: 467
![]() | I think so I own a image hosting site and it inputs the ip with the picture they upload. But I didn't make it lol so have no idea. Also I have one question to ohm how can you make a thumb from a image they user uploads and make it clickable to a full page with the full size image on it I really want to do this for my image host site but have no idea? Thanks.
__________________ My sites: Free Funny Videos Free flash games. Free Banner Exchange DotNameHost Hosting at its best Upload More Files |
| |
| | #24 (permalink) |
| Senior Member Join Date: Oct 2005 Location: Kent ~ U.K.
Posts: 3,209
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | well can anyone tell me? coz this would be really good if i could record the ip? perhaps shanee86, would you mind sending me your php upload script? and i could have a look through it? i may not be able to make a php script, but i can understand and edit it ![]() Thanks - Joe
__________________ Myself and "JackHeskett" are no longer associated with FusedHosting.net. Please pipe all PMs to admin [at] fusedhosting.net. |
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Googlism - What does google think of you? | deadserious | The Break Room | 55 | 12-15-2005 10:09 AM |
| Huge Script Pack for $5 with Resale Rights | dsforsaken | Scripts For Sale | 32 | 12-03-2005 09:46 PM |
| 60.000 Templates, scripts, fonts, banners etc. $9.95 | atkims | Web Development Wanted | 19 | 11-16-2004 10:48 AM |