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 56883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:36:15+00:00 2026-05-10T17:36:15+00:00

I’ve found a few samples online but I’d like to get feedback from people

  • 0

I’ve found a few samples online but I’d like to get feedback from people who use PHP daily as to potential security or performance considerations and their solutions.

Note that I am only interested in uploading a single file at a time.

Ideally no browser plugin would be required (Flash/Java), although it would be interesting to know the benefits of using a plugin.

I would like to know both the best HTML form code and PHP processing code.

  • 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. 2026-05-10T17:36:16+00:00Added an answer on May 10, 2026 at 5:36 pm

    File Upload Tutorial

    HTML

    <form enctype='multipart/form-data' action='action.php' method='POST'>   <input type='hidden' name='MAX_FILE_SIZE' value='1000000' />   <input name='userfile' type='file' />   <input type='submit' value='Go' /> </form> 
    • action.php is the name of a PHP file that will process the upload (shown below)
    • MAX_FILE_SIZE must appear immediately before the input with type file. This value can easily be manipulated on the client so should not be relied upon. Its main benefit is to provide the user with early warning that their file is too large, before they’ve uploaded it.
    • You can change the name of the input with type file, but make sure it doesn’t contain any spaces. You must also update the corresponding value in the PHP file (below).

    PHP

    <?php $uploaddir = '/www/uploads/'; $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);  echo '<pre>'; if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {     echo 'Success.\n'; } else {     echo 'Failure.\n'; }  echo 'Here is some more debugging info:'; print_r($_FILES); print '</pre>'; ?> 

    The upload-to folder should not be located in a place that’s accessible via HTTP, otherwise it would be possible to upload a PHP script and execute it upon the server.

    Printing the value of $_FILES can give a hint as to what’s going on. For example:

         Array     (         [userfile] => Array         (             [name] => Filename.ext             [type] =>              [tmp_name] =>              [error] => 2             [size] => 0         )     ) 

    This structure gives some information as to the file’s name, MIME type, size and error code.

    Error Codes

    0 Indicates that there was no errors and file has been uploaded successfully
    1 Indicates that the file exceeds the maximum file size defined in php.ini. If you would like to change the maximum file size, you need to open your php.ini file, identify the line which reads: upload_max_filesize = 2M and change the value from 2M (2MB) to whatever you need
    2 Indicates that the maximum file size defined manually, within an on page script has been exceeded
    3 Indicates that file has only been uploaded partially
    4 Indicates that the file hasn’t been specified (empty file field)
    5 Not defined yet
    6 Indicates that there´s no temporary folder
    7 Indicates that the file cannot be written to the disk

    php.ini Configuration

    When running this setup with larger files you may receive errors. Check your php.ini file for these keys:

    max_execution_time = 30
    upload_max_filesize = 2M

    Increasing these values as appropriate may help. When using Apache, changes to this file require a restart.

    The maximum memory permitted value (set via memory_limit) does not play a role here as the file is written to the tmp directory as it is uploaded. The location of the tmp directory is optionally controlled via upload_tmp_dir.

    Checking file mimetypes

    You should check the filetype of what the user is uploading – the best practice is to validate against a list of allowed filetypes. A potential risk of allowing any file is that a user could potentially upload PHP code to the server and then run it.

    You can use the very useful fileinfo extension (that supersedes the older mime_content_type function) to validate mime-types.

    // FILEINFO_MIME set to return MIME types, will return string of info otherwise $fileinfo = new finfo(FILEINFO_MIME); $file = $fileinfo->file($_FILE['filename']);  $allowed_types = array('image/jpeg', 'image/png'); if(!in_array($file, $allowed_types)) {     die('Files of type' . $file . ' are not allowed to be uploaded.'); } // Continue 

    More Information

    You can read more on handling file uploads at the PHP.net manual.

    For PHP 5.3+

    //For those who are using PHP 5.3, the code varies. $fileinfo = new finfo(FILEINFO_MIME_TYPE); $file = $fileinfo->file($_FILE['filename']['tmp_name']); $allowed_types = array('image/jpeg', 'image/png'); if(!in_array($file, $allowed_types)) {     die('Files of type' . $file . ' are not allowed to be uploaded.'); } // Continue 

    More Information

    You can read more on FILEINFO_MIME_TYPE at the PHP.net documentation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.