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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:05:06+00:00 2026-06-17T20:05:06+00:00

I’m having some issues with uploading files from HTML to a PHP based web

  • 0

I’m having some issues with uploading files from HTML to a PHP based web server.
The following is my HTML code. No issues here I believe.

<html>
 <body>

  <form action="upload.php" method="post"
   enctype="multipart/form-data" action="2.2.2.cgi">
   <input type="file" name="file" id="file" size="35"><br>
   <input type="submit" name="submit" id="submit" value="Submit">
  </form>

 </body>
</html>

PHP code:

<?php

define ('MAX_FILE_SIZE', 1000000);

$permitted = array('image/gif', 'image/jpeg', 'image/png', 'image/pjpeg', 'text/plain');

if  ($_FILES['file']['type'] == $permitted 
    && $_FILES['file']['size'] > 0 
    && $_FILES['file']['size'] <= MAX_FILE_SIZE) {
      move_uploaded_file($_FILES, $uploadedfile);
      echo ('<img src="'.$uploadedfile'" />');
}
?>

I can’t figure out how to make it work in PHP. I’ve been trying several different ways and the above code is just my latest desperate attempt at figuring it out by trying to store the value into a new variable. What I want to do is the following:

  • Restrict the type and size of files that can be uploaded.
  • Is the file a picture? Display the picture.
  • Is it a plaintext file? Display the contents of the file.
  • Is it an unpermitted file? Display the name, type and size of the file.

Any kind of hint or help in any way would be greatly appreciated. Thanks!

PS. It’s not going live, so any security issues are irrelevant at the moment.

  • 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-06-17T20:05:08+00:00Added an answer on June 17, 2026 at 8:05 pm

    Allright. Totally tested and commented piece of code.

    upload.php

    define ('MAX_FILE_SIZE', 1000000);
    
    $permitted = array('image/gif', 'image/jpeg', 'image/png', 'image/pjpeg', 'text/plain'); //Set array of permitted filetypes
    $error = true; //Define an error boolean variable
    $filetype = ""; //Just define it empty.
    
    foreach( $permitted as $key => $value ) //Run through all permitted filetypes
    {
      if( $_FILES['file']['type'] == $value ) //If this filetype is actually permitted
        {
            $error = false; //Yay! We can go through
            $filetype = explode("/",$_FILES['file']['type']); //Save the filetype and explode it into an array at /
            $filetype = $filetype[0]; //Take the first part. Image/text etc and stomp it into the filetype variable
        }
    }
    
    if  ($_FILES['file']['size'] > 0 && $_FILES['file']['size'] <= MAX_FILE_SIZE) //Check for the size
    {
        if( $error == false ) //If the file is permitted
        {
            move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); //Move the file from the temporary position till a new one.
                  if( $filetype == "image" ) //If the filetype is image, show it!
                  {
                    echo '<img src="upload/'.$_FILES["file"]["name"].'">';
                  }
                  elseif($filetype == "text") //If its text, print it.
                  {
                    echo nl2br( file_get_contents("upload/".$_FILES["file"]["name"]) );
                  }
    
        }
        else
        {
            echo "Not permitted filetype.";
        }
    }
    else
    {
      echo "File is too large.";
    }
    

    Used with this form
    form.html

      <form action="upload.php" method="post"
       enctype="multipart/form-data" action="upload.php">
       <input type="file" name="file" id="file" size="35"><br>
       <input type="submit" name="submit" id="submit" value="Submit">
      </form>
    
     </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm interested in microtypography issues on the web. I want a tool to fix:
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have thousands of HTML files to process using Groovy/Java and I need to
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a bunch of posts stored in text files formatted in yaml/textile (from

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.