Activity Stream
48,167 MEMBERS
6936 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Results 1 to 3 of 3
  1.     
    #1
    Member
    Website's:
    heroturko.biz softpk.com gfxtra.biz hotfilegfx.com

    Default how add file extension for upload files

    Dear sir,

    PDF and excel extension is we only want to allow other files is not allow please help me..


    PHP Code: 
    <?php

        error_reporting
    (E_ALL);
     
        
    /*** the upload directory ***/
        
    $upload_dir'uploads';

        
    /*** numver of files to upload ***/
        
    $num_uploads 5;

        
    /*** maximum filesize allowed in bytes ***/
        
    $max_file_size  5120000000;
     
        
    /*** the maximum filesize from php.ini ***/
        
    $ini_max str_replace('M'''ini_get('upload_max_filesize'));
        
    $upload_max $ini_max 1024;

        
    /*** a message for users ***/
        
    $msg 'Please select files for uploading';

        
    /*** an array to hold messages ***/
        
    $messages = array();

        
    /*** check if a file has been submitted ***/
        
    if(isset($_FILES['userfile']['tmp_name']))
        {
            
    /** loop through the array of files ***/
            
    for($i=0$i count($_FILES['userfile']['tmp_name']);$i++)
            {
                
    // check if there is a file in the array
                
    if(!is_uploaded_file($_FILES['userfile']['tmp_name'][$i]))
                {
                    
    $messages[] = 'No file uploaded';
                }
                
    /*** check if the file is less then the max php.ini size ***/
                
    elseif($_FILES['userfile']['size'][$i] > $upload_max)
                {
                    
    $messages[] = "File size exceeds $upload_max php.ini limit";
                }
                
    // check the file is less than the maximum file size
                
    elseif($_FILES['userfile']['size'][$i] > $max_file_size)
                {
                    
    $messages[] = "File size exceeds $max_file_size limit";
                }
                else
                {
                    
    // copy the file to the specified dir 
                    
    if(@copy($_FILES['userfile']['tmp_name'][$i],$upload_dir.'/'.$_FILES['userfile']['name'][$i]))
                    {
                        
    /*** give praise and thanks to the php gods ***/
                        
    $messages[] = $_FILES['userfile']['name'][$i].' uploaded';
                    }
                    else
                    {
                        
    /*** an error message ***/
                        
    $messages[] = 'Uploading '.$_FILES['userfile']['name'][$i].' Failed';
                    }
                }
            }
        }
    ?>
     <!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>
     <title>Multiple File Upload</title>
     </head>

     <body>
     
     <h3><?php echo $msg?></h3>
     <p>
     <?php
        
    if(sizeof($messages) != 0)
        {
            foreach(
    $messages as $err)
            {
                echo 
    $err.'<br />';
            }
        }
     
    ?>
     </p>
     <form enctype="multipart/form-data" action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>" method="post">
     <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size?>" />
     <?php
        $num 
    0;
        while(
    $num $num_uploads)
        {
            echo 
    '<div><input name="userfile[]" type="file" /></div>';
            
    $num++;
        }
     
    ?>

     <input type="submit" value="Upload" />
     </form>

     </body>
     </html>
    softpk Reviewed by softpk on . how add file extension for upload files Dear sir, PDF and excel extension is we only want to allow other files is not allow please help me.. <?php error_reporting(E_ALL); Rating: 5

  2.   Sponsored Links

  3.     
    #2
    Member
    Website's:
    wscripts.net damnlolscript.com lulzjet.com
    check the extensions and allow only those that you want.

    get the extension
    PHP Code: 
    $ext substr($filenamestrrpos($filename'.') + 1); 
    allow only pdf and excel
    PHP Code: 
    $allowed = array('pdf','xsl');
    if(
    in_array($ext,$allowed)) upload(); 
    your code (not tested)
    PHP Code: 
    <?php

        error_reporting
    (E_ALL);
     
        
    /*** the upload directory ***/
        
    $upload_dir'uploads';

        
    /*** numver of files to upload ***/
        
    $num_uploads 5;

        
    /*** maximum filesize allowed in bytes ***/
        
    $max_file_size  5120000000;
     
        
    /*** the maximum filesize from php.ini ***/
        
    $ini_max str_replace('M'''ini_get('upload_max_filesize'));
        
    $upload_max $ini_max 1024;

        
    /*** a message for users ***/
        
    $msg 'Please select files for uploading';

        
    /*** an array to hold messages ***/
        
    $messages = array();
        
        
    //allowed extensions
        
    $allowed = array('pdf','xls');

        
    /*** check if a file has been submitted ***/
        
    if(isset($_FILES['userfile']['tmp_name']))
        {
            
    /** loop through the array of files ***/
            
    for($i=0$i count($_FILES['userfile']['tmp_name']);$i++)
            {
                
    $filename basename($_FILES['userfile']['name'][$i]);
                
    $ext substr($filenamestrrpos($filename'.') + 1);
                if(
    in_array($ext,$allowed)) {
                    
    // check if there is a file in the array
                    
    if(!is_uploaded_file($_FILES['userfile']['tmp_name'][$i]))
                    {
                        
    $messages[] = 'No file uploaded';
                    }
                    
    /*** check if the file is less then the max php.ini size ***/
                    
    elseif($_FILES['userfile']['size'][$i] > $upload_max)
                    {
                        
    $messages[] = "File size exceeds $upload_max php.ini limit";
                    }
                    
    // check the file is less than the maximum file size
                    
    elseif($_FILES['userfile']['size'][$i] > $max_file_size)
                    {
                        
    $messages[] = "File size exceeds $max_file_size limit";
                    }
                    else
                    {
                        
    // copy the file to the specified dir 
                        
    if(@copy($_FILES['userfile']['tmp_name'][$i],$upload_dir.'/'.$_FILES['userfile']['name'][$i]))
                        {
                            
    /*** give praise and thanks to the php gods ***/
                            
    $messages[] = $_FILES['userfile']['name'][$i].' uploaded';
                        }
                        else
                        {
                            
    /*** an error message ***/
                            
    $messages[] = 'Uploading '.$_FILES['userfile']['name'][$i].' Failed';
                        }
                    }
                }
                else {
                    
    $messages[] = 'Uploading '.$_FILES['userfile']['name'][$i].' Failed. Extension not allowed.';
                }
            }
        }
    ?>
     <!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>
     <title>Multiple File Upload</title>
     </head>

     <body>
     
     <h3><?php echo $msg?></h3>
     <p>
     <?php
        
    if(sizeof($messages) != 0)
        {
            foreach(
    $messages as $err)
            {
                echo 
    $err.'<br />';
            }
        }
     
    ?>
     </p>
     <form enctype="multipart/form-data" action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>" method="post">
     <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size?>" />
     <?php
        $num 
    0;
        while(
    $num $num_uploads)
        {
            echo 
    '<div><input name="userfile[]" type="file" /></div>';
            
    $num++;
        }
     
    ?>

     <input type="submit" value="Upload" />
     </form>

     </body>
     </html>

  4.     
    #3
    Member
    Website's:
    heroturko.biz softpk.com gfxtra.biz hotfilegfx.com
    Thank You So Much

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 5
    Last Post: 23rd May 2012, 08:56 AM
  2. Buying / Renting a server for down and upload files to File Hosts.
    By M.D.House in forum File Host Discussion
    Replies: 1
    Last Post: 29th Nov 2011, 05:39 PM
  3. [Selling] MirrorScript - upload your files to multiple file hosting sites! - by PixelScripts
    By devNULL in forum Completed Transactions
    Replies: 1
    Last Post: 30th Oct 2011, 05:43 PM
  4. Replies: 1
    Last Post: 20th Jul 2011, 04:31 PM
  5. Hide / show remote file extension
    By CatchItBaby in forum Technical Help Desk Support
    Replies: 1
    Last Post: 9th Dec 2010, 07:51 PM

Tags for this Thread

BE SOCIAL