
December 15th, 2008, 05:44 PM
|
|
Registered User
|
|
Join Date: Dec 2008
Posts: 1
Time spent in forums: 33 m 56 sec
Reputation Power: 0
|
|
|
Need some help with file upload script
Hi, I would love some help in making a upload status bar for this php file upload script I use for my site Appscene . Any help would really be appreciated.
Code is as follow
Code:
<?php
/*
AppScene.org Upload Script
Coded by:newhen
*/
mysql_connect("localhost", "appscene", "******");
mysql_select_db("appscene_uploads");
//ini_set("upload_tmp_dir","temp/");
//set_time_limit(0);
// upload config
$maxsize = 106971520; // in bytes
$up_dir = "files/"; // upload dir
$dispdir = "files/"; // upload dir
$page_title = "AppScene - You crack it, We host it.";
$allowed = array(
"application/x-itunes-ipa",
"application/octet-stream",
"application/zip",
"application/x-rar-compressed"
);
$ext = array(
"application/x-itunes-ipa" => ".ipa",
"application/octet-stream" => ".ipa",
"application/zip" => ".ipa",
"application/x-rar-compressed" => ".rar",
);
// end config
function r() {
$charset = "0123456789abcdefghijklmnopqrstuvwxyz";//
$number = rand( 0, strlen($charset) );
return $charset{$number} ? $charset{$number} : "a";
}
function newname(){
$out = time();
return $out;
}
function clean($clean){
$clean = htmlentities($clean);
return $clean;
}
function nclean($clean){
$clean = htmlentities($clean);
return $clean;
}
function upload(){
global $maxsize;
global $up_dir;
global $dispdir;
global $allowed;
global $ext;
$host = clean($_SERVER["HTTP_HOST"]);
$file_name = nclean($_FILES['userfile']['name']);
$temp_name = $_FILES['userfile']['tmp_name'];
$file_type = $_FILES['userfile']['type'];
$file_size = $_FILES['userfile']['size'];
$result = $_FILES['userfile']['error'];
//File Name Check
if ( $file_name == "" || substr_count($file_name, ".php") ){
$message = "<br><br>Invalid file name specified.";
return $message;
}
//File Size Check
else if ( $file_size > $maxsize) {
$message = "<br><br>Sorry, the filesize limit is 100MB.";
return $message;
}
//File Type Check
else if ( !in_array($file_type, $allowed) ){
$message = "<br><br>Sorry, that filetype isn't allowed." ;
return $message;
}
//return "$temp_name : $outfile : <a href=\"http://$host/$outfile\">http://$host/$outfile</a><br />";
$sqldate = date("ymdHis");
$ip = clean($_SERVER["REMOTE_ADDR"]);
$file_name = str_ireplace($ext[$file_type],"",$file_name);
$sqlname = mysql_real_escape_string($file_name);
$fileoln = str_ireplace(".", "-", $file_name);
$newname = newname();
$outfile = $up_dir.$fileoln.".$newname".$ext[$file_type]; //$newname.
$dispfile = $dispdir.$fileoln.".$newname".$ext[$file_type];
$result = move_uploaded_file($temp_name, $outfile);
chmod($outfile, 0755);
$scs = "<br><br>File: <a href=\"http://$host/$dispfile\">http://$host/$dispfile</a>";
$fal = "Somthing went wrong with upload. Try again in a few minutes.";
if($result){
mysql_query("INSERT INTO `files` (`id` ,`name`, `type` ,`path` ,`date` ,`ip` ) VALUES ( NULL , '$sqlname', '$file_type', '$outfile', '$sqldate', '$ip' )");
return $scs;
}else
return $fal;
}
$useragent = strtolower(clean($_SERVER["HTTP_USER_AGENT"]));
if (!empty($_FILES))
$greet = upload();
include ('header.php');
echo '<div class="outerbox">';
echo '<div class="uploadbox">';
echo '<div class="uploadbox">';
echo '<form class="form" enctype="multipart/form-data" method="POST" onSubmit="document.getElementById(\'uploading\').innerHTML = \'<br /><b>Uploading...</b>\'">';
echo '<form class="form" enctype="multipart/form-data" method="POST" onSubmit="document.getElementById(\'uploading\').innerHTML = \'<br /><b>Uploading...</b>\'">';
echo '<s>Multiple Files</s> | Max File Size: 100MB<br>';
echo '<input name="userfile" type="file" size="50" /><div id="uploading"></div>';
echo '<input name="userfile" type="file" size="50" /><div id="uploading"></div>';
echo $greet;
echo '<br><br>';
echo '<input type="image" src="/img/upload.png" value="Upload File" /></input>';
echo '</form>';
echo '</div>';
echo '<p class="tos">All files uploaded are the sole responsibility of the user. AppScene.org will not be held responsible for the actions of our users. We hold no responsibility of your files due to data loss or downtime. Please use AppScene responsibly. </p>';
include ('footer.php');
echo '</div>';
echo '</body>';
echo '</html>';
|