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

  • Home
  • SEARCH
  • 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 6953063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:25:49+00:00 2026-05-27T14:25:49+00:00

I know this topic is widely talked about. I’ve done my research, and decided

  • 0

I know this topic is widely talked about. I’ve done my research, and decided to store image files onto the server instead of the DB as a blob file. The problem that I am having is trying to figure out the best way to upload the file, store it in a designated folder then storing the destination in the db..say../img/something.jpg – I’ve tried looking through many resources but most of them are missing some important steps in the process.

Problems:

  1. Finding a secure way for uploading the img file
  2. Limiting the file
  3. size Uploading the image to a destination file
  4. Storing the destination file as a text in the DB

I’m using PHP and MySQL.

  • 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-27T14:25:50+00:00Added an answer on May 27, 2026 at 2:25 pm

    Here you go, this covers the basic ideas of what you want to do:

    <?php
        $allowedTypes = array("image/jpg", "image/jpeg", "image/png");
        $maxSize = 3 * 1024 * 1024; // 3Mb
    
        $fileType = $_FILES["file"]["type"];
        $fileSize = $_FILES["file"]["size"];
    
        // check if there was an error
        if ($_FILES["file"]["error"] > 0)
        {
            die($_FILES["file"]["error"]);
        }
    
        // check if the filetype is valid
        if (!in_array($fileType, $allowedTypes))
        {
            die("Invalid file type: $fileType");
        }
    
        // check if the size doesn't exceed the limitations
        if ($fileSize > $maxSize)
        {
            die("The file was too big: $fileSize");
        }
    
        $name = $_FILES["file"]["name"];
        $tmpfile = $_FILES["file"]["tmp_name"];
    
        // check if the filename is valid
        if (preg_match("/[\w-]+\.(jpg|jpeg|png)$/", $name) != 1)
        {
            die("Invalid file name: $name");
        }
    
        // create unique name if needed
    
        $path = "/var/www/images/" . $name;
    
        move_uploaded_file($tmpfile, $path);
    
        // add the filepath to mysql
        mysql_connect("localhost", "username", "password");
        mysql_select_db("imagedb");
        mysql_query("INSERT INTO images (Location, Size) VALUES ('$path', '$size');");
    ?>
    

    This is meant to show how it could be done.

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

Sidebar

Related Questions

I know that there are many different questions about this sort of topic on
I know this topic is asked before but they were not about jqueryui. Therefore
I know we already have many posts about this topic, but I just cannot
I know this topic is done to death but I am at wits end.
I did a lot of research about this topic and didn't yet find a
So there are a few things I know about this topic but I am
I know there's a lot of questions about this topic but I have not
First of all, I know there is a lot of questions about this topic.
I know this topic was descibed few times so far, but here is mine
I know this topic is bit old, but i did surf the web and

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.