3v4l.org

run code in 300+ PHP versions simultaneously
<? /* //================================================================================ * phphq.Net Custom PHP Scripts * //================================================================================ :- Script Name: phUploader :- Version: 1.3 :- Release Date: June 23rd 2004 :- Last Updated: Jan 23 2010 :- Author: Scott Lucht <scott@phphq.net> http://www.phphq.net :- Copyright (c) 2010 All Rights Reserved :- :- This script is free software; you can redistribute it and/or modify :- it under the terms of the GNU General Public License as published by :- the Free Software Foundation; either version 2 of the License, or :- (at your option) any later version. :- :- This script is distributed in the hope that it will be useful, :- but WITHOUT ANY WARRANTY; without even the implied warranty of :- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the :- GNU General Public License for more details. :- http://www.gnu.org/licenses/gpl.txt :- //================================================================================ * Description //================================================================================ :- phUploader is a script for uploading single or multiple images or files to your website. You can specify your :- own file extensions that are accepted, the file size and naming options. This script was built and tested on :- IIS6/7 and Apache 2+. It's recommended to use php 5.1+ This script is very useful for temporary file :- storage or simple sig and avatar hosting. //================================================================================ * Setup //================================================================================ :- To setup this script, upload phUploader.php to a folder on your server. Create a new folder named uploads :- and chmod it to 777. Edit the variables below to change how the script acts. Please read the notes if you :- don't understand something. //================================================================================ * Change log //================================================================================ :- Version 1.0 :- 1) Initial Release :- Version 1.1 :- 1) Minor bug fixes :- 2) Enabled multiple file uploads :- Version 1.2 :- 1) Added CSS styling :- 2) Removed automatic creation of file upload folder. :- 3) Improved cookie security by hashing password and storing it within the cookie for authentication. :- 4) Minor bug fixes :- Version 1.3 :- 1) Re-write of many core functions to increase security. :- 2) Patched a vulnerability that allowed a remote attacker to upload a file with two extensions and then :- remotely execute the script on a vulnerable web server. <http://www.securityfocus.com/bid/25405> :- 3) New feature allows files that pass validation to be uploaded while files that fail validation are not :- uploaded without rejecting to whole group of files. :- 4) Fixed a flaw that allowed files with blank names or un-sanitized names to be uploaded which may :- cause issues for some users. :- 5) Minor bug fixes //================================================================================ * Frequently Asked Questions //================================================================================ :- Q1: I always get an error that the files were not uploaded. IE: GENERAL ERROR :- 1) Make sure you have CHMOD your "uploads" folder to 777 using your FTP client or similar. If you do :- not know how to do this ask your hosting provider. :- 2) Make sure the uploads folder actually exists. This is the second most common mistake aside from :- improper permissions. :- 3) If you are having problems uploading after you have chmod the uploads folder 777, try using the :- full server path in $fullpath below. If you do not know this ask your host. :- 4) Make sure "file_uploads" is set to ON in php.ini :- :- Q2: The page takes long to load and then gives me a page cannot be displayed or a blank page. :- 1) This is usually due to a low value in php.ini for "max_execution_time". :- 2) A newer ini setting "max_file_uploads" in php 5.2.12 was added which may be limiting the number of simultaneous uploads. :- 3) Your "upload_max_filesize" and "post_max_size" in php.ini might be set to low. :- :- Q3: How do I edit the colors of the form? :- 1) You will need to edit the CSS near the bottom of the script to change the looks and colors of the form. :- Check http://www.w3schools.com/css/default.asp for more information on CSS. :- :- Q4: Can I remove your copyright link? :- 1) I can't physically stop you. However, I really appreciate it when people leave it intact. :- Some people donate $5, $10, $20 to take it off. :- :- Q5: You never respond to my emails or to my questions in your forums! :- 1) I'm a very busy guy. I'm out of town a lot, and at any given time I have several projects going on. :- I get a lot of emails about this script, not to mention my other ones. :- 2) I only understand English. If your English is very bad please write in your native language and then :- translate it to English using <http://babelfish.altavista.com/babelfish/tr>. :- 3) If you are going to contact me, describe the issue you are having as completly as possible. :- "dude me form don't work see it at blah.com what's wrong??!?!" will get no response, ever. Write :- in detail what the problem is. Spend a minute on it, and maybe I'll take some of my time to reply. :- /* //================================================================================ * ! ATTENTION ! //================================================================================ :- Please read the above FAQ before giving up or emailing me. It may sort out your problems! */ // Max size PER file in KB $max_file_size="512"; // Max size for all files COMBINED in KB $max_combined_size="2048"; //Maximum file uploades at one time $file_uploads="4"; //The name of your website $websitename="Your site name"; // Full browser accessable URL to where files are accessed. With trailing slash. $full_url="http://YOUR_SITE/uploads/"; // Path to store files on your server If this fails use $fullpath below. With trailing slash. $folder="./uploads/"; // Use random file names? true=yes (recommended), false=use original file name. // Random names will help prevent files being denied because a file with that name already exists. $random_name=true; // Types of files that are acceptiable for uploading. Keep the array structure. $allow_types=array("jpg","gif","png","zip","rar","txt","doc"); // Only use this variable if you wish to use full server paths. Otherwise leave this empty. With trailing slash. $fullpath=""; //Use this only if you want to password protect your upload form. $password=""; /* //================================================================================ * ! ATTENTION ! //================================================================================ : Don't edit below this line. */ // Initialize variables $password_hash=md5($password); $error=""; $success=""; $display_message=""; $file_ext=array(); $password_form=""; // Function to get the extension a file. function get_ext($key) { $key=strtolower(substr(strrchr($key, "."), 1)); $key=str_replace("jpeg","jpg",$key); return $key; } // Filename security cleaning. Do not modify. function cln_file_name($string) { $cln_filename_find=array("/\.[^\.]+$/", "/[^\d\w\s-]/", "/\s\s+/", "/[-]+/", "/[_]+/"); $cln_filename_repl=array("", ""," ", "-", "_"); $string=preg_replace($cln_filename_find, $cln_filename_repl, $string); return trim($string); } // If a password is set, they must login to upload files. If($password) { //Verify the credentials. If($_POST['verify_password']==true) { If(md5($_POST['check_password'])==$password_hash) { setcookie("phUploader",$password_hash); sleep(1); //seems to help some people. header("Location: http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']); exit; } } //Show the authentication form If($_COOKIE['phUploader']!=$password_hash) { $password_form="<form method=\"POST\" action=\"".$_SERVER['PHP_SELF']."\">\n"; $password_form.="<table align=\"center\" class=\"table\">\n"; $password_form.="<tr>\n"; $password_form.="<td width=\"100%\" class=\"table_header\" colspan=\"2\">Password Required</td>\n"; $password_form.="</tr>\n"; $password_form.="<tr>\n"; $password_form.="<td width=\"35%\" class=\"table_body\">Enter Password:</td>\n"; $password_form.="<td width=\"65%\" class=\"table_body\"><input type=\"password\" name=\"check_password\" /></td>\n"; $password_form.="</tr>\n"; $password_form.="<td colspan=\"2\" align=\"center\" class=\"table_body\">\n"; $password_form.="<input type=\"hidden\" name=\"verify_password\" value=\"true\">\n"; $password_form.="<input type=\"submit\" value=\" Verify Password \" />\n"; $password_form.="</td>\n"; $password_form.="</tr>\n"; $password_form.="</table>\n"; $password_form.="</form>\n"; } } // If Password // Dont allow submit if $password_form has been populated If(($_POST['submit']==true) AND ($password_form=="")) { //Tally the size of all the files uploaded, check if it's over the ammount. If(array_sum($_FILES['file']['size']) > $max_combined_size*1024) { $error.="<b>FAILED:</b> All Files <b>REASON:</b> Combined file size is to large.<br />"; // Loop though, verify and upload files. } Else { // Loop through all the files. For($i=0; $i <= $file_uploads-1; $i++) { // If a file actually exists in this key If($_FILES['file']['name'][$i]) { //Get the file extension $file_ext[$i]=get_ext($_FILES['file']['name'][$i]); // Randomize file names If($random_name){ $file_name[$i]=time()+rand(0,100000); } Else { $file_name[$i]=cln_file_name($_FILES['file']['name'][$i]); } // Check for blank file name If(str_replace(" ", "", $file_name[$i])=="") { $error.= "<b>FAILED:</b> ".$_FILES['file']['name'][$i]." <b>REASON:</b> Blank file name detected.<br />"; //Check if the file type uploaded is a valid file type. } ElseIf(!in_array($file_ext[$i], $allow_types)) { $error.= "<b>FAILED:</b> ".$_FILES['file']['name'][$i]." <b>REASON:</b> Invalide file type.<br />"; //Check the size of each file } Elseif($_FILES['file']['size'][$i] > ($max_file_size*1024)) { $error.= "<b>FAILED:</b> ".$_FILES['file']['name'][$i]." <b>REASON:</b> File to large.<br />"; // Check if the file already exists on the server.. } Elseif(file_exists($folder.$file_name[$i].".".$file_ext[$i])) { $error.= "<b>FAILED:</b> ".$_FILES['file']['name'][$i]." <b>REASON:</b> File already exists.<br />"; } Else { If(move_uploaded_file($_FILES['file']['tmp_name'][$i],$folder.$file_name[$i].".".$file_ext[$i])) { $success.="<b>SUCCESS:</b> ".$_FILES['file']['name'][$i]."<br />"; $success.="<b>URL:</b> <a href=\"".$full_url.$file_name[$i].".".$file_ext[$i]."\" target=\"_blank\">".$full_url.$file_name[$i].".".$file_ext[$i]."</a><br /><br />"; } Else { $error.="<b>FAILED:</b> ".$_FILES['file']['name'][$i]." <b>REASON:</b> General upload failure.<br />"; } } } // If Files } // For } // Else Total Size If(($error=="") AND ($success=="")) { $error.="<b>FAILED:</b> No files selected<br />"; } $display_message=$success.$error; } // $_POST AND !$password_form /* //================================================================================ * Start the form layout //================================================================================ :- Please know what your doing before editing below. Sorry for the stop and start php.. people requested that I use only html for the form.. */ ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Language" content="en-us" /> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title><?php echo $websitename; ?> - Powered By phUploader</title> <style type="text/css"> body{ background-color:#FFFFFF; font-family: Verdana, Arial, sans-serif; font-size: 12pt; color: #000000; } .message { font-family: Verdana, Arial, sans-serif; font-size: 11pt; color: #000000; background-color:#EBEBEB; } a:link, a:visited { text-decoration:none; color: #000000; } a:hover { text-decoration:none; color: #000000; } .table { border-collapse:collapse; border:1px solid #000000; width:450px; } .table_header { border:1px solid #000000; background-color:#C03738; font-family: Verdana, Arial, sans-serif; font-size: 11pt; font-weight:bold; color: #FFFFFF; text-align:center; padding:2px; } .upload_info { border:1px solid #000000; background-color:#EBEBEB; font-family: Verdana, Arial, sans-serif; font-size: 8pt; color: #000000; padding:4px; } .table_body { border:1px solid #000000; background-color:#EBEBEB; font-family: Verdana, Arial, sans-serif; font-size: 10pt; color: #000000; padding:2px; } .table_footer { border:1px solid #000000; background-color:#C03738; text-align:center; padding:2px; } input,select,textarea { font-family: Verdana, Arial, sans-serif; font-size: 10pt; color: #000000; background-color:#AFAEAE; border:1px solid #000000; } .copyright { border:0px; font-family: Verdana, Arial, sans-serif; font-size: 9pt; color: #000000; text-align:right; } form { padding:0px; margin:0px; } </style> <? If($password_form) { Echo $password_form; } Else { ?> <form action="<?=$_SERVER['PHP_SELF'];?>" method="post" enctype="multipart/form-data" name="phuploader"> <table align="center" class="table"> <tr> <td class="table_header" colspan="2"><b><?=$websitename;?></b> </td> </tr> <?If($display_message){?> <tr> <td colspan="2" class="message"> <br /> <?=$display_message;?> <br /> </td> </tr> <?}?> <tr> <td colspan="2" class="upload_info"> <b>Allowed Types:</b> <?=implode($allow_types, ", ");?><br /> <b>Max size per file:</b> <?=$max_file_size?>kb.<br /> <b>Max size for all files combined:</b> <?=$max_combined_size?>kb.<br /> </td> </tr> <?For($i=0;$i <= $file_uploads-1;$i++) {?> <tr> <td class="table_body" width="20%"><b>Select File:</b> </td> <td class="table_body" width="80%"><input type="file" name="file[]" size="30" /></td> </tr> <?}?> <tr> <td colspan="2" align="center" class="table_footer"> <input type="hidden" name="submit" value="true" /> <input type="submit" value=" Upload File(s) " /> &nbsp; <input type="reset" name="reset" value=" Reset Form " onclick="window.location.reload(true);" /> </td> </tr> </table> </form> <?}//Please leave this here.. it really dosen't make people hate you or make your site look bad.. ?> <table class="table" style="border:0px;" align="center"> <tr> <td><div class="copyright">&copy;<a href="http://www.phphq.net/?script=phUploader" target="_blank" title="Uploader Powered By phUploader &lt;www.phphq.net&gt;">phUploader</a></div></td> </tr> </table> </body> </html>

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.60.0100.00718.43
8.3.50.0120.00921.92
8.3.40.0060.00918.76
8.3.30.0100.00320.31
8.3.20.0020.00520.21
8.3.10.0080.00022.04
8.3.00.0050.00322.34
8.2.180.0140.00416.63
8.2.170.0090.00622.96
8.2.160.0140.00022.08
8.2.150.0050.00324.18
8.2.140.0000.00824.66
8.2.130.0030.00626.16
8.2.120.0000.00821.08
8.2.110.0040.00422.02
8.2.100.0080.00418.03
8.2.90.0040.00419.31
8.2.80.0050.00319.26
8.2.70.0040.00417.75
8.2.60.0050.00517.93
8.2.50.0050.00318.07
8.2.40.0000.00818.22
8.2.30.0000.00718.07
8.2.20.0040.00417.77
8.2.10.0050.00317.86
8.2.00.0000.01017.92
8.1.270.0040.00424.66
8.1.260.0040.00426.35
8.1.250.0000.00728.09
8.1.240.0030.00624.01
8.1.230.0080.00419.34
8.1.220.0080.00017.80
8.1.210.0030.00618.77
8.1.200.0000.00817.35
8.1.190.0000.00817.53
8.1.180.0030.00618.10
8.1.170.0000.00818.61
8.1.160.0040.00418.89
8.1.150.0060.00318.65
8.1.140.0070.00017.44
8.1.130.0050.00317.39
8.1.120.0050.00317.49
8.1.110.0000.00717.43
8.1.100.0070.00017.31
8.1.90.0030.00317.40
8.1.80.0040.00417.53
8.1.70.0000.00717.29
8.1.60.0030.00617.55
8.1.50.0000.00717.41
8.1.40.0040.00417.55
8.1.30.0040.00417.58
8.1.20.0040.00417.70
8.1.10.0070.00017.59
8.1.00.0000.00717.49
8.0.300.0000.00718.77
8.0.290.0000.00717.30
8.0.280.0000.00718.56
8.0.270.0040.00417.23
8.0.260.0070.00016.82
8.0.250.0070.00017.14
8.0.240.0060.00317.08
8.0.230.0070.00017.11
8.0.220.0000.00717.07
8.0.210.0000.00816.98
8.0.200.0080.00217.05
8.0.190.0000.00916.98
8.0.180.0000.00817.09
8.0.170.0000.00817.09
8.0.160.0030.00317.05
8.0.150.0000.00716.89
8.0.140.0040.00416.95
8.0.130.0000.00613.53
8.0.120.0070.00016.89
8.0.110.0050.00316.92
8.0.100.0040.00416.82
8.0.90.0040.00416.91
8.0.80.0030.01217.01
8.0.70.0040.00416.89
8.0.60.0040.00416.83
8.0.50.0000.00716.98
8.0.30.0090.01217.18
8.0.20.0120.00717.40
8.0.10.0070.00017.13
8.0.00.0110.00916.83
7.4.330.0020.00215.00
7.4.320.0060.00016.60
7.4.300.0040.00416.50
7.4.290.0000.00716.53
7.4.280.0040.00416.55
7.4.270.0030.00316.44
7.4.260.0030.00316.39
7.4.250.0000.00716.59
7.4.240.0030.00416.56
7.4.230.0070.00016.54
7.4.220.0180.00616.51
7.4.210.0070.00816.53
7.4.200.0030.00316.40
7.4.190.0000.00716.70
7.4.160.0080.00816.65
7.4.150.0090.00917.40
7.4.140.0100.00817.86
7.4.130.0140.00616.56
7.4.120.0140.00716.52
7.4.110.0150.00416.61
7.4.100.0060.01116.64
7.4.90.0060.01416.55
7.4.80.0070.01119.39
7.4.70.0150.00616.37
7.4.60.0130.00316.38
7.4.50.0060.00316.31
7.4.40.0100.00322.77
7.4.30.0110.00716.50
7.3.330.0000.00513.47
7.3.320.0060.00013.47
7.3.310.0000.00716.50
7.3.300.0030.00316.43
7.3.290.0070.01016.43
7.3.280.0110.00516.41
7.3.270.0070.01017.40
7.3.260.0160.00716.46
7.3.250.0100.01016.57
7.3.240.0090.00916.38
7.3.230.0080.00816.55
7.3.210.0070.01016.47
7.3.200.0110.00719.39
7.3.190.0110.01116.50
7.3.180.0080.00816.43
7.3.170.0160.00416.46
7.3.160.0090.00916.63
7.2.330.0090.00916.74
7.2.320.0080.01116.70
7.2.310.0120.00616.63
7.2.300.0030.00416.64
7.2.290.0100.00716.64
7.1.70.0000.01016.88
7.1.60.0070.01819.43
7.1.50.0060.00617.03
7.1.00.0030.04722.34
7.0.200.0260.00414.66
7.0.140.0070.07022.00
7.0.100.0100.08720.02
7.0.90.0070.09020.06
7.0.80.0100.07320.00
7.0.70.0070.08720.04
7.0.60.0130.07719.96
7.0.50.0200.06020.36
7.0.40.0000.05720.05
7.0.30.0100.05720.10
7.0.20.0030.05020.10
7.0.10.0130.08019.97
7.0.00.0000.09020.02
5.6.280.0000.07321.17
5.6.250.0130.07720.72
5.6.240.0100.07720.58
5.6.230.0070.08020.64
5.6.220.0170.07320.63
5.6.210.0030.05720.76
5.6.200.0130.07321.04
5.6.190.0030.06020.94
5.6.180.0130.07021.08
5.6.170.0200.07021.01
5.6.160.0070.07721.11
5.6.150.0100.07721.07
5.6.140.0030.07721.18
5.6.130.0100.05021.17
5.6.120.0000.05721.06
5.6.110.0130.08021.11
5.6.100.0070.09021.10
5.6.90.0070.08321.10
5.6.80.0000.04320.41
5.6.70.0070.03720.39
5.6.60.0030.03720.32
5.6.50.0070.03720.32
5.6.40.0100.08020.44
5.6.30.0100.08320.54
5.6.20.0070.07720.44
5.6.10.0030.04020.40
5.6.00.0000.04720.23
5.5.380.0100.06720.39
5.5.370.0170.06720.42
5.5.360.0070.07320.45
5.5.350.0030.08320.45
5.5.340.0130.08020.91
5.5.330.0030.08720.91
5.5.320.0130.07320.74
5.5.310.0030.05020.64
5.5.300.0070.07720.74
5.5.290.0100.07320.93
5.5.280.0070.04020.74
5.5.270.0070.06720.73
5.5.260.0030.09320.90
5.5.250.0130.07720.71
5.5.240.0130.03320.29
5.5.230.0030.04320.30
5.5.220.0030.04020.16
5.5.210.0100.03320.16
5.5.200.0130.05020.28
5.5.190.0030.06320.18
5.5.180.0130.06720.00
5.5.160.0030.05320.15
5.5.150.0100.03720.20
5.5.140.0100.03320.25
5.5.130.0070.03720.18
5.5.120.0100.03320.28
5.5.110.0070.03720.16
5.5.100.0070.03720.08
5.5.90.0030.04020.09
5.5.80.0000.04320.07
5.5.70.0100.03320.07
5.5.60.0030.04020.06
5.5.50.0030.04720.00
5.5.40.0070.05319.94
5.5.30.0070.04020.11
5.5.20.0070.04020.05
5.5.10.0000.04320.02
5.5.00.0030.04720.04
5.4.450.0070.05319.46
5.4.440.0000.08719.38
5.4.430.0100.08019.35
5.4.420.0070.07319.21
5.4.410.0070.05319.25
5.4.400.0030.04019.04
5.4.390.0070.04019.16
5.4.380.0000.04319.23
5.4.370.0100.03019.02
5.4.360.0030.08319.12
5.4.350.0070.06719.13
5.4.340.0030.03719.23
5.4.320.0000.04019.12
5.4.310.0030.03719.16
5.4.300.0030.03719.16
5.4.290.0070.04019.09
5.4.280.0070.03719.02
5.4.270.0030.03718.87
5.4.260.0030.04319.01
5.4.250.0000.04718.95
5.4.240.0030.03718.97
5.4.230.0100.03018.95
5.4.220.0070.03719.03
5.4.210.0030.03319.13
5.4.200.0070.04319.04
5.4.190.0100.02719.04
5.4.180.0000.04019.04
5.4.170.0030.05718.91
5.4.160.0000.04019.02
5.4.150.0030.04719.02
5.4.140.0000.04016.46
5.4.130.0000.04716.41
5.4.120.0030.03716.41
5.4.110.0030.03316.49
5.4.100.0030.03716.54
5.4.90.0070.04016.44
5.4.80.0070.03316.54
5.4.70.0070.03716.43
5.4.60.0130.05016.36
5.4.50.0070.07316.32
5.4.40.0000.06716.53
5.4.30.0070.05316.45
5.4.20.0030.07016.53
5.4.10.0000.03716.38
5.4.00.0100.06315.86
5.3.290.0070.03714.65
5.3.280.0000.03714.56
5.3.270.0030.03314.50
5.3.260.0000.04014.62
5.3.250.0070.03714.57
5.3.240.0070.03014.59
5.3.230.0030.03714.46
5.3.220.0070.03314.43
5.3.210.0000.04014.43
5.3.200.0000.04314.44
5.3.190.0030.04014.43
5.3.180.0030.03314.58
5.3.170.0030.04714.43
5.3.160.0030.04014.43
5.3.150.0030.08014.52
5.3.140.0030.07314.42
5.3.130.0070.07714.54
5.3.120.0130.07014.50
5.3.110.0070.04314.52
5.3.100.0100.06313.96
5.3.90.0000.05713.88
5.3.80.0100.07314.04
5.3.70.0130.06314.01
5.3.60.0030.07714.00
5.3.50.0030.08013.95
5.3.40.0030.05013.91
5.3.30.0070.06713.69
5.3.20.0100.07013.55
5.3.10.0100.04313.64
5.3.00.0070.03713.51

preferences:
52.52 ms | 401 KiB | 5 Q