SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Oct 2005
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Upload File Max File Size Problem

    Im trying to create a upload script to upload some images. However it wont upload any images that are over 2.15 mb. Can anyone help? script is below

    UPLOAD FORM

    PHP Code:
    <?php //  ini_set ('display_errors', true ); 
    require_once('../spaw/spaw_control.class.php');
    require_once(
    '../../classes/admin.class.php'); ?>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>EPC Website Administration: Occasional Papers</title>
    <link href="../../css/epc_admin.css" rel="stylesheet" type="text/css" />
    <script language="JavaScript" type="text/JavaScript">
    <!--
    function BRB_PHP_DelWithCon(deletepage_url,field_name,field_value,messagetext) { //v1.0 - Deletes a record with confirmation
      if (confirm(messagetext)==1){
          location.href = eval('\"'+deletepage_url+'?'+field_name+'='+field_value+'\"');
      }
    }
    //-->
    </script>
    <script src="../../includes/sorttable.js"></script>
    </head>

    <body>
    <div id="heading">
    <div class="clear"></div>
    </div>

    <div id="main">
    <form method="post" action="add.php" enctype="multipart/form-data">
    <table border="0" cellpadding="0" cellspacing="0" class="editform" id="diary">
        <tr>
           <th scope="row">File:</th>
           <input type="hidden" name="max_file_size" value="3000" />
          <td><input type="file" name="userfile" size="50" /></td>
        </tr>
        <tr>
          <th scope="row">&nbsp;</th>
          <td><input name="Submit" type="submit" title="Sumbit" value="Save"/></td>
        </tr>
    </table>
    </form>
    <p>&nbsp;</p>
    </div>
    </body>
    </html>

    UPLOAD SCRIPT

    PHP Code:
    <?php 
    require_once('../../classes/admin.class.php');


    //Catch the file uploaded
    $userfile $_FILES['userfile']['tmp_name'];
    $userfile_name $_FILES['userfile']['name'];
    $userfile_size $_FILES['userfile']['size'];
    $userfile_type $_FILES['userfile']['type'];
    $userfile_error $_FILES['userfile']['error'];

    if (
    $userfile_error 0)
    {
        
    $msg 'Problem: ';
        switch (
    $userfile_error)
            {
            case 
    1: echo 'File exceeded uploaded_max_filesize'; break;
            case 
    2: echo 'File exceeded max_file_size'; break;
            case 
    3: echo 'File only partially uploaded'; break;
            case 
    4: echo 'No file uploaded'; break;
            }
        exit;
    }

    $upfile 'C:/Inetpub/wwwroot/demo1/upload/'.$userfile_name;

    if (
    is_uploaded_file($userfile))
    {
        if (!
    move_uploaded_file($userfile$upfile))
        {
            
    $msg 'Problem: Could not move file to destination directory';
            exit;
        }
    }
    else
    {
         
    $msg 'Possible file upload attack. Filename: '.$userfile_name;
         exit;
    }

    $msg 'File: '.$userfile_name.' uploaded succesfully';    

    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>EPC Website Administration:  Occasional Papers</title>
    <link href="../../css/epc_admin.css" rel="stylesheet" type="text/css" />
    <script language="JavaScript" type="text/JavaScript">
    <!--
    function BRB_PHP_DelWithCon(deletepage_url,field_name,field_value,messagetext) { //v1.0 - Deletes a record with confirmation
      if (confirm(messagetext)==1){
          location.href = eval('\"'+deletepage_url+'?'+field_name+'='+field_value+'\"');
      }
    }
    //-->
    </script>
    <script src="../../includes/sorttable.js"></script>
    </head>

    <body>
    <div id="heading">
    <h1><a href="../index.php">Website Adminstration</a>:  Occasional Papers </h1>
    <img src="/images/global/logo.gif" alt="EPC Logo" width="110" height="105"  />
    <div class="clear"></div>
    </div>

    <div id="main">
    [<a href="index.php">Add Another Image</a>]</p>
    <p><?php echo $msg?></p>

  2. #2
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You have to increase upload_max_filesize in your php.ini, as this is by default set to 2MB. Ask the hosting company to do it for you. Aslo, check the post_max_size. I think, by default it is set to 8MB.
    -- Jelena --

  3. #3
    SitePoint Evangelist
    Join Date
    Oct 2005
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    my hosts take ages to reply is there a way of checking those details through a php script at all?

  4. #4
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you can create an .htaccess file, create one and put the follwing lines:

    php_value upload_max_filesize 120M
    php_value post_max_size 120M
    php_value max_input_time 7200
    LimitRequestBody 125829190
    php_value max_execution_time 7200
    php_value memory_limit 120M

    Or any value you want. You must also raise input time, default is 30s.
    Here input time is 7200 sec ( 2h ) and max size is 120M

    And then do a phpinfo() to see if it's ok.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •