Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1082131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:15:28+00:00 2026-05-16T22:15:28+00:00

I am trying to upload files using php, and it works perfectly up until

  • 0

I am trying to upload files using php, and it works perfectly up until 1Mb, I already checked the forum and saw that the common thing missing was to edit this values on php.ini (I am using WAMP):

post_max_size = 8G upload_max_filesize
= 2G

as you can see I already changed them up to Gigabytes and still it isn’t working, what happens is that I click on upload and it goes to my upload.php file and just hangs in there writing nothing into the DB.

I had this in my HTML but I commented it already:

<!--input type="hidden" name="MAX_FILE_SIZE" value="20000000000" /-->

my upload php is:

<?php
include("mysql.class.php");
$mysql = new MySQL();
$tbl_name="documento";
session_start();

if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0){
    $fileName = $_FILES['userfile']['name'];
    $tmpName  = $_FILES['userfile']['tmp_name'];
    $fileSize = $_FILES['userfile']['size'];
    $fileType = $_FILES['userfile']['type'];

    $fp      = fopen($tmpName, 'r');
    $content = fread($fp, filesize($tmpName));
    $content = addslashes($content);
    fclose($fp);
    $myusername=$_SESSION['myusername'];
    if(!get_magic_quotes_gpc()){
        $fileName = addslashes($fileName);
    }

    $query = "INSERT INTO $tbl_name (name, size, type, archivo,user_username ) ".
    "VALUES ('$fileName', '$fileSize', '$fileType', '$content','$myusername')";

    mysql_query($query) or die('Error, query failed'); 


    echo "<br>File $fileName uploaded<br>";
    header("location:admin.php");
} 
?>

What am I missing here? Also, when I upload images (since 180kbs) and I download them to check they uploaded correctly I am not able to see the image however documents have no problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T22:15:28+00:00Added an answer on May 16, 2026 at 10:15 pm
    $fp = fopen($tmpName, 'r');
    $content = fread($fp, filesize($tmpName));
    $content = addslashes($content);
    fclose($fp);
    

    You’re escaping the contents of the file. That will mostly be the cause that image doesn’t get displayed. Escaping should take place when you’re about to send data to remote targets (use htmlentities() for sending ‘text’ to the browser, use mysql_real_escape_string for sending data to the MySQL database). You should take a look in the PHP manual, how to correctly implement file uploading.

    When uploading a file to PHP, follow these rules:

    1. Check whether a file is uploaded or not: isset($_FILES['userfile'])
    2. Check whether the file upload was successful ($_FILES['userfile']['error'] === 0). If not, display a corresponding error message. See this page for possible errors.
    3. Check the file size (maximum size): $_FILES['userfile']['size'] < 102400 (limits the file size to 100 kB)
      (optionally check whether the file is empty or not, this depends on your application)
    4. If you’re going to use the file name, sanitize it, by stripping out forbidden characters: $sanitizedFileName = preg_replace('#[^a-z0-9_-]#i', '', $_FILES['userfile']['name']);
    5. Check the extension on the sanitized name, whether it’s allowed or not:

      $allowedExtensions = array('png', 'jpg', 'jpeg', 'txt', 'gif');
      $dotPos = strrchr($_FILES['userfile']['name'], '.');
      $ext = '';
      // Both FALSE and 0 will not match, I consider 'htaccess' in '.htaccess' not as an extension
      if($dotPos){
         // we are not interested whether the extension is in uppercase or lowercase
         $ext = strtolower(substr($_FILES['userfile']['name'], $dotPos));
      }
      if(!in_array($ext, $allowedExtensions)){
         echo 'Extension not allowed';
      }
      else{
         // continue with uploading
      }
      
    6. Optionally, use image functions to verify an image, and limit the dimension (width x height) with getimagesize().

    7. Use move_uploaded_file($_FILES['userfile'], "$targetDir/$sanitizedFileName") or store the contents (file_get_contents($_FILES['userfile']['tmp_name'])) in the database.
      When storing in the database, do not forget to escape your data.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write some PHP to upload a file to a folder on
I'm trying to upload documents to SharePoint using web services attaching custom metadata to
I am trying to upload a file or stream of data to our web
In my code attached below, I'm trying to upload a file via ASP.NET. I
I am trying to do a file upload from gwt-ext without bringing up the
I am trying to find out how to upload a file from a web
I'm trying to craete a site which allows users to upload any file type
I'm trying to upload an application to the iPhone App Store, but I get
I'm trying to upload an image to my site through a form, however it's
I'm trying to do the following: User goes to web page, uploads XLS file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.