SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2012
    Location
    Web
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    File Upload Warning post content-length of bytes exceeds the limit

    I am making a file upload system. The user chooses where to upload using the dynamic drop down list. And this is the problem I am facing right now. This is my form.

    Code:
    <form action="uploader.php" method="POST" enctype="multipart/form-data" name="uploads">
    
                <label for="file">Choose a file: </label> 
    
                    <input type="file" name="userfile" id="userfile"><br/><br/>
    
                        <select id="text-one" name="one"> 
    
                            <option selected value="base">Select Department</option>
                            <option value="CSE" name="cse">Computer Science Engineering</option>
                            <option value="ECE" name="ece">Electronics & Communication Engineering</option>
                            <option value="MECH" name="mech">Mechanical Engineering</option>
    
                        </select>
    
                        <br /><br/>
    
                        <select id="text-two" name="two">
                            <option>Select Semester</option>
                        </select>
    
                        <br /><br/>
    
                        <select id="text-three" name="three">
                            <option>Select Subject</option>
                        </select>
    
                        <br/><br/>
    
                <button class ="btn btn-primary" button type="submit" name="upload" value="Upload" onClick="val()">Upload</button>
    
            </form>
    And this is my other php file to which it is linked.

    PHP Code:
    <?php
    if(isset($_POST['upload']))

      
    $path1=$_POST['one']."/"
      
    $path2=$_POST['two']."/"
      
    $path3=$_POST['three']."/";   
      
    $upload_path=$path1.$path2.$path3;
     }
    else
     {
      echo 
    "Select a Subject";
      echo 
    "<br>";
    }
    $allowed_filetypes = array('.doc','.docx','.jpg','.jpeg','.png','.ppt','.pptx','.xls','.xlsx','.pdf','.txt','.zip','.rar'); 
    $max_filesize 20000000
    $filename $_FILES['userfile']['name']; 
    $ext substr($filenamestrpos($filename,'.'), strlen($filename)-1);
    if(!
    in_array($ext,$allowed_filetypes))
      die(
    "<SCRIPT LANGUAGE='JavaScript'>
            window.alert('You cannot upload the following type of file!')
            window.location.href='upload.php';
         </SCRIPT>"
    );
    if(
    filesize($_FILES['userfile']['size']) > $max_filesize)
      die(
    "<SCRIPT LANGUAGE='JavaScript'>
            window.alert('The file you attempted to upload is too large!')
            window.location.href='upload.php';
         </SCRIPT>"
    );
    if(!
    is_writable($upload_path))
      die(
    "<SCRIPT LANGUAGE='JavaScript'>
            window.alert('You cannot upload to the specified directory!')
            window.location.href='upload.php';
         </SCRIPT>"
    );
    if(
    move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path $filename))
      echo (
    "<SCRIPT LANGUAGE='JavaScript'>
              window.alert('Your file has been uploaded successfully')
              window.location.href='upload.php';
            </SCRIPT>"
    );
    else
      echo (
    "<SCRIPT LANGUAGE='JavaScript'>
              window.alert('There was an error during the file upload!')
              window.location.href='upload.php';
            </SCRIPT>"
    );
    ?>
    I have edited the phpini file with the following settings and also made a .htaccess file in the php folder.

    upload_max_filesize 25M post_max_size 25M memory_limit 64M

    But when I intentionally upload a file greater than 25 MB, I get the error as given in the title. Also, considering the max file size is being violated, it does not give the error related to the file size, i.e The file you attempted to upload is too large, it says You cannot upload the following type of file. And in the background that post length warning thing comes.

    Please help me with this. I am on my localhost.

  2. #2
    SitePoint Zealot
    Join Date
    Jun 2011
    Location
    Kolding, Denmark
    Posts
    108
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)
    Does $_FILES['userfile']['error'] has any error?

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2012
    Location
    Web
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When I echo that it again redirects me and shows I cannot upload the following type of file and not the file attempted to upload is too large. However in the background it shows about the post content length exceeding and notice indexed file thing.

  4. #4
    SitePoint Zealot
    Join Date
    Jun 2011
    Location
    Kolding, Denmark
    Posts
    108
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)
    You can comment out the redirect part to see what errors you're getting. Also make sure, that file you are uploading has lowercase extension as in $allowed_filetypes array.

  5. #5
    SitePoint Enthusiast
    Join Date
    Nov 2012
    Location
    Web
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, I will add the strtolower function to it. Not a prob. But all my extensions are in lower case anyways. No, even if I don't comment it out, in the background I am getting the error.


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
  •