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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:51:48+00:00 2026-05-16T15:51:48+00:00

i wanna download any file from any website with my forcedownload script. simple script

  • 0

i wanna download any file from any website with my forcedownload script. simple script which just prompts a download window to save the file to the desktop. I simply pass ?path=http://www.google.com/images/whatever/file.jpg to the url and the script fires the download.

However this script is of course not working for every page. Most of the time I don’t have the permissions to do so!

HTTP request failed! HTTP/1.0 403 Forbidden in ….

Is there a method where i can check if the forcedownload from some domain would work or not.
Like is_readable() or something.

regards matt

edit:

    <?php
    error_reporting(E_ALL);

    if(isset($_GET['p'])) $path = $_GET['p'];
    else header('Location:' . 'mypage');

    $file = $path;
    //header('Location:' . $file);
    //
    header("Cache-Control: no-cache");
    header("Expires: -1");
    header("Content-Type: application/octet-stream;");
    header("Content-Disposition: attachment; filename=\"" . basename($file) . "\";");
    header("Content-Transfer-Encoding: binary");
    //header("Content-Length: " . filesize($file));
    //echo file_get_contents($file);
    echo readfile($file);
    ?>
  • 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-16T15:51:49+00:00Added an answer on May 16, 2026 at 3:51 pm

    I created this class for my mediawiki word count project.

    // Copyright PHPExperts.pro
    // License: Any user on Stackflow may use this code under the BSD License.
    
    /**
    * Web page datatype that holds all the various parts
    * and info about a web page.
    */
    class WebPage
    {
        public $url;
        public $headers;
        public $body;
        public $text;
    
    
        public function __construct($url)
        {
            // 1. Bail out now if the CURL extension is not loaded.
            if (!in_array('curl', get_loaded_extensions()))
            {
                throw new Exception(WebPageException::MISSING_CURL);
            }
    
            // 2. Make sure the URL is valid.
            self::ensureValidURL($url);
    
            // 3. Store the URL.
            $this->url = $url;
        }
    
        /**
        * Determine if a URL is valid.
        *
        * @param string $url
        * @returns true if the URL is a string and is a valid URL. False, otherwise.
        */
        public static function isURLValid($url)
        {
            return (is_string($url) &&
                    filter_var($url, FILTER_VALIDATE_URL) !== false);
        }
    
        public static function ensureValidURL($url)
        {
            if (!self::isURLValid($url))
            {
                throw new WebPageException(WebPageException::INVALID_URL, array($url));
            }
        }
    
        // captureHeader() donated by bendavis78@gmail.com,
        // via http://us.php.net/curl_setopt_array
        private function captureHeader($ch, $header)
        {
            $this->headers[] = $header;
            return strlen($header);
        }
    
        public function fetchURL()
        {
            $ch = curl_init();
            curl_setopt_array($ch, array(CURLOPT_URL => $this->url,
                                         CURLOPT_RETURNTRANSFER => 1,
                                         CURLOPT_HEADERFUNCTION => array($this, 'captureHeader'),
                                         CURLOPT_TIMEOUT => 5,
                                         )
                             );
    
            $data = curl_exec($ch);
            curl_close($ch);
    
            if ($data === false || is_null($data) || $data == '')
            {
                throw new WebPageException(WebPageException::BLANK_URL, array($this->url));
    
            }
    
            // TODO: Need to handle HTTP error messages, such as 404 and 502.
            $this->body = $data;
                    // Uses code from php@wizap.dom
                    $this->text = remove_HTML($data);
        }
    }
    

    After you run WebPage::captureHeader() you then just foreach through $this->headers, and if you don’t find a HTTP/1.0 403 Forbidden, you’re good to go.

    This thoroughly answers your question, so I expect credit.

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

Sidebar

Related Questions

I wanna use php to download some zip files from a url. I.E. sitename.com/path/to/file/id/123
I'm talking about getting a file download to computer without letting user know any
Wanna run an application from maven command line, any command?
I've got a problem with QFtp. I wanna download a single .txt file with
I Wanna download file for further use, this is the best way I've found,
i wanna creat a website for downloading some files (pdf,word,xls, such as these files),
I wanna upload/update file by System.IO.FileStream in Google Documents List API(C#)? I use two
I wanna use powershell to get all the file in sharepoint library EM_DOC_LIBRARY and
I wanna run selenium tests from TeamCity using Maven at Linux server without display.
I wanna implement a download-and-install mechanism. I have a source link where my app

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.