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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:17:52+00:00 2026-05-27T09:17:52+00:00

OK I decided to retry it into another way.. This is my code the

  • 0

OK I decided to retry it into another way.. This is my code the bad part is now it keep saying invalid file size.

<?php
      session_start();
      include "connect.php";
      if ( $_POST[ "submit" ] ) {
             if ( $_SESSION[ "name" ] ) {
                    $name = $_FILES[ "file" ][ "name" ];
                    $type = $_FILES[ "file" ][ "type" ];
                    $size = $_FILES[ "file" ][ "size" ];
                    $tmp_name = $_FILES[ "file" ][ "tmp_name" ];
                    $error = $_FILES[ "file" ][ "error" ];
                    if ( $type == "image/jpeg" || $type == "image/gif" ) {
                           if ( $size > 1100000 && $size < 1700000 ) {
                                  if ( $error > 0 ) {
                                         echo "Error!!!!!!" . $error;
                                  } else {
                                         if ( file_exists( "upload/" . $name ) ) {
                                                echo $name . " already exists.";
                                         }
                                  }
                           } else {
                                  $location = "upload/" . $name;
                                  move_uploaded_file( $tmp_name , $location );
                                  $user = $_SESSION[ "name" ];
                                  $sqlcode = mysql_query( "INSERT INTO tblFile (id,user,location) VALUES ('','$user','$location')" );
                                  echo "<a href='$location'>Click here to view your image.</a>";
                           }
                    }
             } else {

                    echo "Please check the size of your File..";
             }
      } else {
             echo "Invalid file format.";
      }

 ?>

the index is:

<?php

session_start();
$_SESSION["name"] = "Admin";

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>File Upload</title>
<link href="styles.css" type="text/css" rel="stylesheet" />
</head>
<body>


<form enctype="multipart/form-data" action="upload.php" method="post">

Select File: <input type="file" name="uploadFile">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000"/>
<input name="Submit" type="submit" value="Upload File">

</form>

If it is not one thing with this file/upload it is something else. I still have to be able to user uploads a .png or .jpg file, resize the image to a thumbnail and keep a copy of both the thumbnail and regular size image in a folder. And be able to insert the data into a new table in your database. I think I am alittle closer than before.

  • 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-27T09:17:52+00:00Added an answer on May 27, 2026 at 9:17 am

    Try this, I have reconstructed and ‘clean’ your code.

    <?php
    session_start();
    include "connect.php";
    
    if($_POST['submit']) {
       $name = $_FILES['file']['name'];
       $type = $_FILES['file']['type'];
       $size = $_FILES['file']['size'];
       $tmp_name = $_FILES['file']['tmp_name'];
       $error = $_FILES['file']['error'];
       if($type == "image/jpeg" || $type == "image/gif" || $type == "image/pjpeg")
       {
         if($size > 1100000 && $size < 1700000)
         {
           if($error > 0)
             echo "Error Upload #: " . $error;
           else
           {
             if(file_exists("upload/" . $name))
               echo $name . " already exists.";
             else
             {
               $location = "upload/" . $name;
               move_uploaded_file( $tmp_name , $location );
               $user = $_SESSION[ "name" ];
               $sqlcode = mysql_query( "INSERT INTO tblFile (id,user,location) VALUES ('','$user','$location')" );
               echo "<a href='$location'>Click here to view your image.</a>";
              }
            }
          }
          else
          {
            echo "Invalid file size.";
          }
       }
       else
         echo "Invalid file format.";
    }
    else
        // invalid due to post submit not set
    ?>
    

    And also, apply changes suggested by @jakenoble. <input type="hidden" name="MAX_FILE_SIZE" value="2000000"/>

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

Sidebar

Related Questions

I decided to code a website where each rewritten URL has its own file,
I decided to dig into the ActiveRecord code for Rails to try and figure
Decided to use Apache's Common Configuration package to parse an XML File. I decided
I decided to try http://www.screwturn.eu/ wiki as a code snippet storage utility. So far
We decided to use the minimumRequiredVersion in our clickOnce application manifest, and now when
Decided to move one of my project from iBatis to MyBatis and ran into
I decided that the easiest way to rename the directory is through the REN
I decided to move Entity Connection String from app.config to code. However after setting
I decided to dive into perl with some of the starter scripts on their
I decided to learn Django Forms. For a while now, I have been using

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.