All pastes #798485 Raw Edit

Someone

public text v1 · immutable
#798485 ·published 2007-11-26 20:58 UTC
rendered paste body
<!--Upload script by %eax(eax.gopzap.com). Email: eax@eax.gopzap.com-->
<script type="text/javascript">
function upload() { 
var show = document.getElementById('up_img'); 
if (show.style.display=="none"){ 
show.style.display=''; 
} 
}
</script>
<?php
ob_start();
/*
** Configuration
*/

$conf['upload'] = true; /* True to allow, false to deny */

/*
** Protection cookie configuration
*/

$conf['cookie']['use'] = false; /* Use protection cookie */
$conf['cookie']['time'] = 1; /* Time in minutes */
$conf['cookie']['name'] = "mhs_upload"; /* Cookie name */

/*
** Directories & Extensions
*/

$conf['dir']['name'] = "yb"; /* Directory name to upload (without backslash at the end) */
$conf['dir']['encrypt'] = false; /* Encrypt file name using MD5 so there won't be equal names (true or false), if this option is false, the file will be renamed to its file number on the upload directory */
$conf['dir']['uhash'] = false; /* When encrypt is set to true, you can select on using md5 or just using the file name without the extension... */
$conf['dir']['formats'] = array('png','jpg','jpeg','gif','bmp'); /* Allowed extensions to be uploaded */
$conf['dir']['filesize'] = "2097152"; /* Max file size */

/*
** Logging and informating
*/

$conf['inf']['log'] = true; /* Log who uploads? (true or false) */
$conf['inf']['file'] = "upload.log"; /* File to log everyone who uploads a file */

/*
** Code starts!... Don't touch unless you know what you are doing!
*/

if(!function_exists('scandir')) {
    function scandir($dir, $sortorder = 0) {
        if(is_dir($dir) && $dirlist = @opendir($dir)) {
            while(($file = readdir($dirlist)) !== false) {
                $files[] = $file;
            }
            closedir($dirlist);
            ($sortorder == 0) ? asort($files) : rsort($files); // arsort was replaced with rsort
            return $files;
        } else return false;
    }
}

if ($conf['upload'] != true) { die("Uploader is blocked from the configuration!."); }

if (!isset($_POST) || empty($_POST) || empty($_FILES['upload']['name'])) {
        echo "<form method=\"POST\" enctype=\"multipart/form-data\" action=\"\">\n";
        echo "<input type='hidden' name='max_file_size' value='{$conf['dir']['filesize']}'>\n";
        echo "File Loaction: <input type=\"file\" name=\"upload\"><br>\n";
        echo "<input type=\"submit\" value=\"Upload\" name=\"upload\" onclick=\"upload()\"><br>\n";
		echo "<div style=\"display:none;\" id=\"up_img\"><img src=\"images/loading_img.gif\"></div>\n";
        echo "</form>\n";
        ob_end_flush();
}
elseif ($conf['cookie']['use'] == true && isset($_COOKIE[$conf['cookie']['name']])) {
        echo "You already have uploaded a file in lower than ".$conf['cookie']['time']." minutes... Please wait!<br>\n";
        ob_end_flush();
}
else {
        if (!is_dir($conf['dir']['name']) && !mkdir($conf['dir']['name'],0777)) {
                echo "Couldn't upload file, the directory ".$conf['dir']['name']." doesn't exists!...<br>\n";
                ob_end_flush();
        }
        // Retrieve the file extension...
        $gext = explode(".",$_FILES['upload']['name']);
        $ext = $gext[(count($gext)-1)];
        $noext = str_replace(".".$ext,"",$_FILES['upload']['name']);
        unset($gext);
        if (!is_numeric(array_search($ext,$conf['dir']['formats']))) {
                echo 'Only the following extensions are valid: ';
                foreach ($conf['dir']['formats'] as $myval) { echo "<b>".$myval."<b> "; }
                echo "<br>\n";
                ob_end_flush();
        }
        if (!isset($conf['dir']['encrypt']) || $conf['dir']['encrypt'] == false) {
                $listfiles = scandir($conf['dir']['name']);
                if ($listfiles == false) {
                        echo "Couldn't list the upload directory!...<br>\n";
                        ob_end_flush();
                }
                $files = 0;
                foreach ($listfiles as $val) { if ($val != "." && $val != ".." && !is_dir($val)) { $files++; } }
                unset($listfiles);
                $file['fullname'] = "{$files}.{$ext}";
                $file['name'] = $files;
                if (is_file($file['fullname'])) {
                        echo "Random error while renaming your file!...<br>\n";
                        ob_end_flush();
                }
        }
        else {
                if ($conf['dir']['uhash'] == true) { $mfile = md5($noext).rand(1,999999999999); }
                else { $mfile = $noext.rand(1,999999999999); }
                $file['fullname'] = $mfile.".".$ext;
                $file['name'] = $mfile;
                unset($mfile);
                if (is_file($file['fullname'])) {
                        echo "Your file can't be renamed as a file with the same renamed name exists. Please try again!...<br>\n";
                        ob_end_flush();
                }
        }
        $file['extension'] = $ext;
        if($_FILES['upload']['error'] != 0 && $_FILES['upload']['error'] != 2) {
                echo "Random error while uploading your file!...<br>\n";
                ob_end_flush();
        }
        elseif($_FILES['upload']['error'] == 2) {
                echo "Your file size is higher than ".round(($conf['dir']['filesize']/1048576),1)." MB (megabytes)...<br>\n";
                ob_end_flush();
        }
        if(move_uploaded_file($_FILES['upload']['tmp_name'],"{$conf['dir']['name']}/{$file['fullname']}")) {
                $buildurl = $_SERVER["SERVER_NAME"]."/";
                $mhu = explode("/",$_SERVER["REQUEST_URI"]);
                for ($x = 0; $x < (count($mhu)-2); $x++) { if ($x != count($mhu)) { $buildurl .= $mhu[$x]."/"; } }
                $buildurl .= "{$conf['dir']['name']}/{$file['fullname']}";
                unset($mhu);
				$file_link = str_replace(array('.png','.jpg','.jpeg','.gif','.bmp','.PNG','.JPG','.JPEG','.GIF','.BMP'),'',$file['fullname']);
                echo "Your file has been successfully uploaded!. Click <a href=\"http://mhs.scupe.net/?page_id=view&id=$file_link\">here</a> to see it!.<br>\n";
				echo "Or <a href=\"http://mhs.scupe.net/?page_id=upload\">Upload</a>  again!\n";
                if ($conf['cookie']['use'] == true) {
                        setcookie($conf['cookie']['name'],$file['fullname'],time()+($conf['cookie']['time']*60));
                }
                if ($conf['inf']['log'] == true) {
                        if (getenv('HTTP_CLIENT_IP')) { $ip = getenv('HTTP_CLIENT_IP'); }
                        elseif (getenv('HTTP_X_FORWARDED_FOR')) { $ip = getenv('HTTP_X_FORWARDED_FOR'); }
                        elseif (getenv('HTTP_X_FORWARDED')) { $ip = getenv('HTTP_X_FORWARDED'); }
                        elseif (getenv('HTTP_FORWARDED_FOR')) { $ip = getenv('HTTP_FORWARDED_FOR'); }
                        elseif (getenv('HTTP_FORWARDED')) { $ip = getenv('HTTP_FORWARDED'); }
                        else { $ip = $_SERVER['REMOTE_ADDR']; }

                        $fload = fopen($conf['inf']['file'],"a");
                        fwrite($fload,"=> Uploaded file {$file['fullname']} by user @ IP {$ip}\n");
                        fclose($fload);
                        unset($fload,$ip);
                }
        }
        else {
                echo "Couldn't upload the file!...<br>\n";
        }
}
ob_end_flush();
?>