PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old December 15th, 2008, 04:44 PM
newhen newhen is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Dec 2008
Posts: 1 newhen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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>';

Reply With Quote
  #2  
Old December 17th, 2008, 12:41 PM
watdaflip watdaflip is offline
Contributing User
Click here for more information
 
Join Date: Apr 2007
Posts: 114 watdaflip User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 15 h 17 m 34 sec
Reputation Power: 3
An upload status bar will require some javascript/ajax, php itself isn't capable of this. I would suggest using a js framework such as mootools, which has an upload progress bar called FancyUpload which uses mootools framework. It will only require minimal javascript knowledge to use. There are several other frameworks like jquery or dojo.. although I'm not sure if they have an upload progress bar made for them.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > Need some help with file upload script


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT