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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:27:32+00:00 2026-05-29T04:27:32+00:00

I need a php file with the ability to download multiple images per se

  • 0

I need a php file with the ability to download multiple images per se from a folder on my server, with an unique ID per image.

e.g.

I have an image on my server: /home/example/public_html/multipleimage/2.png

And I want to download that image through the unique php file: http://example.com/file.php

I would type the following url: http://example.com/file.php?id=2
And the browser would have to return the image.

But… how should be the php file?
Can it be done without going through a database?

Thanks.

  • 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-29T04:27:34+00:00Added an answer on May 29, 2026 at 4:27 am
    <?php
    header("Content-Type: image/png");
    readfile(
        sprintf(
            '/home/example/public_html/multipleimage/%d.png', 
            $_GET['id']
        )
    );
    

    See the following entries in the PHP Manual:

    • header – Send a raw HTTP header
    • readfile – Reads a file and writes it to the output buffer.
    • sprintf – Returns a string produced according to the formatting string format.
    • $_GET – associative array of variables passed to the current script via the URL parameters

    Note that I am using sprintf with %d, so it will silently convert any non-numeric id value to 0, so a malicious input like ../../etc/passwd will try to read 0.png. If you want to use anything else but numbers, you need to sanitize the input to prevent directory traversal attacks and null byte poisoning (before PHP 5.3.4):

    • filter_input – Gets a specific external variable by name and optionally filters it
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a simple proxy PHP function/script that can download a file from a
I have a PHP file that I need it to detect it's directory it's
I have a file as documentRoot/app/webroot/myFile.php I need to be able to access this
I have an XML file which I need to parse using PHP and send
i need in an php file three drop down boxes or multiple select boxes.
I'm receiving a date field from a php file, and I need to format
I have a PHP file that I would like to run once per day.
I need to call a Perl script from a PHP file, and I've gotten
I need to load a PHP file into a variable. Like include(); I have
I need to get information from a php file and put the information in

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.