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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:54:27+00:00 2026-06-08T13:54:27+00:00

After doing research, I found that it is more recommended to save the image

  • 0

After doing research, I found that it is more recommended to save the image name in database and the actual image in a file directory. Two of the few reasons is that it is more safer and the pictures load a lot quicker. But I don’t really get the point of doing this procedure because every time I retrieve the pictures with the firebug tool i can find out the picture path in the file directory which can lead to potential breach.

Am I doing this correctly or it is not suppose to show the complete file directory path of the image?

PHP for saving image into database

$images = retrieve_images();
    insert_images_into_database($images);

    function retrieve_images()
    {        
        $images = explode(',', $_GET['i']);

        return $images;
    }

    function insert_images_into_database($images)
    {
        if(!$images) //There were no images to return
            return false;        

       $pdo = get_database_connection();

        foreach($images as $image)
        {

            $path = Configuration::getUploadUrlPath('medium', 'target');
            $sql = "INSERT INTO `urlImage` (`image_name`) VALUES ( ? )";

            $prepared = $pdo->prepare($sql);
            $prepared->execute(array($image));
            echo ('<div><img src="'. $path . $image . '" /></div>');
        }
    }
  • 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-08T13:54:29+00:00Added an answer on June 8, 2026 at 1:54 pm

    One method to achieve what you originally intended to do by storing images in database is still continue to serve image via a PHP script, thus:

    1. Shielding your users from knowing the actual path of an image.
    2. You can, and should have, images stored outside of your DocumentRoot, so that they are not able to be served by web server.

    Here’s one way you can achieve that through readfile():

    <?php
    // image.php
    
    // Translating file_id to image path and filename
    $path = getPathFromFileID($_GET['file_id']);
    $image = getImageNameFromFileID($_GET['file_id']);
    
    // Actual full path to the image file
    // Hopefully outside of DocumentRoot
    $file = $path.$image;
    
    if (userHasPermission()) {
        readfile($file);
    }
    else {
        // Better if you are actually outputting an image instead of echoing text
        // So that the MIME type remains compatible
        echo "You do not have the permission to load the image";
    }
    
    exit;
    

    You can then serve the image by using standard HTML:

    <img src="image.php?file_id=XXXXX"> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After doing lot of research in Google, I found this program: #include <stdio.h> int
after I did some research on the subject, I found that Windows Live stopped
Firstly, I'm some what new to C++/CLI . After doing some research I've found
After doing some research on the subject, I've been experimenting a lot with patterns
I am building my own torrent site and after doing some research I have
After taking a look at this SO question and doing my own research, it
I am doing some research into platform independent code and found mention of the
I have created an app that sends intents among multiple activities. After doing some
I have done some research and found that I can use: string retUrl =
after doing some research i'm still not sure if using mysql with .net desktop

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.