Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Upload status script

Posted on 2005-05-09
1
Medium Priority
?
747 Views
Last Modified: 2013-12-12
How can I write a upload status script for my picture upload script. here is the upload script. If the upload script can be put on a seperate page that would be better and just require() it with this upload script.

<?php
$myback = "model-picture-form.php";
$limitedext = array("image/gif","image/jpg","image/jpeg","image/pjpeg", "image/bmp");

$uploaddir = 'pictures/';

$count = isset( $_POST["count"] ) ? intval( $_POST["count"] ) : 1;

for( $i = 1; $i <= $count; $i++ )
{
    if( isset($_FILES['img'.$i]) && !empty($_FILES['img'.$i]['tmp_name']) )
    {
        $tmp_filename = $_FILES['img'.$i]['tmp_name'];

        $filename = basename($_FILES['img'.$i]['name']);

        $filetype = $_FILES['img'.$i]['type'];

        $filesize = $_FILES['img'.$i]['size'];

        $uploadfile = $uploaddir . $filename;

        $fileext = strrchr($filename, '.');

        // Return error if the file-size is greater than 30000 bytes.
        if( $filesize > 30000 )
        {
            echo "<br><br>Sorry, File size is bigger than 30 KB and has not uploaded.<p> Please go back an find a picture with a smaller file size. <a href='$myback'>Back To Form</a>";
        }
        else
        {
           if( in_array(strtolower($filetype), $limitedext) )
           {
               if ( $handle = opendir($uploaddir) )
               {
                   while ( false !== ( $file = readdir($handle) ) )
                   {
                       if ( $file != "." && $file != ".." )
                       {
                           if( strtolower($file) == strtolower($filename) )
                           {
                               $changed_file_name = basename( $filename, $fileext ) . '_' . date("YmdHis") . $fileext;
                               $uploadfile = $uploaddir . $changed_file_name;
                           }
                       }
                   }
                   closedir( $handle );
               }

               if ( move_uploaded_file($tmp_filename, $uploadfile) )
               {
                     chmod( $uploadfile, 0755 );
                     print ". <br><br>File is valid, and was successfully uploaded. <a href='$uploadfile' target=\"_blank\">Click here</a> to view the file";
               }
               else
               {
                     print "<br><br>Possible file upload attack!  Here's some debugging info:\n";
                     print_r($_FILES);
               }
           }
           else
           {
              echo ". <br><br>Invalid file and not uploaded. Please upload only JPG or GIF or BMP file.";
           }
        }
    }
}

?>
0
Comment
Question by:smphil
1 Comment
 
LVL 32

Accepted Solution

by:
ldbkutty earned 1500 total points
ID: 13965086
http://www.raditha.com/php/progress.php

=========
The answer that we came up with mixes PHP with perl. On most servers where PHP is installed you are certain to find perl as well.
=========
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question