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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:53:44+00:00 2026-06-07T03:53:44+00:00

I have searched the web for 2 days and can not find the answer.

  • 0

I have searched the web for 2 days and can not find the answer.

I am trying to create a routine which displays the files on a site I control, and allows the user to download a selected file to a local drive.

I am using the code below. When I uncomment the echo statements, it displays the correct source and destination directories, the correct file size and the echo after the fclose displays TRUE.

When I echo the source file ($data), it displays the correct content.

The $FileName variable contains the correct filename, which is either .doc/.docx or .pdf. I have tested both and neither saves anything into the destination directory, or anywhere else on my machine.

The source path ($path) is behind a login, but I am already logged in.

Any thoughts on why this is failing to write the file?

Thanks,
Hank

Code:

$path = "https://.../Reports/ReportDetails/$FileName";
/* echo "Downloading: $path"; */
$data = file_get_contents($path); /* echo "$data"; */
$dest = "C:\MyScans\\".$FileName; /* echo "<br />$dest"; */
$fp = fopen($dest,'wb');
if ( $fp === FALSE ) echo "<br />Error in fopen";
$result = fwrite($fp,$data);
if ( $result === FALSE ) echo "<br />Can not write to $dest";
/* else echo "<br />$result bytes written"; */
$result = fclose($fp); /* echo "<br />Close: $result"; */
  • 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-07T03:53:45+00:00Added an answer on June 7, 2026 at 3:53 am

    I think (!) that you’re a bit confused.

    You mentioned

    allows the user to download a selected file to a local drive.

    But the path "C:\MyScans\\".$FileName is is the path on the webserver, not the path on the user’s own computer.

    After you do whatever to retrieve the desired file from the remote website:

    1. Create a file from it and redirect the user to the file by using header('Location: /path/to/file.txt');

    2. Insert the following header:

      header('Content-disposition: attachment; filename=path/to/file.txt');

    It forces the user to download the file. And that’s probably what you want to do

    Note: I have used the extension txt, but you can use any extension

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

Sidebar

Related Questions

I have searched the web for days now but I can't seem to find
I have searched the web for hours but I can not find anything about
I have searched the web but could not find an answer. how do I
I have searched the web a while and I can't find the answer to
I have searched for 3 days the web to find a solution to my
I have searched the web but I cannot find the solution to my problem.
Windows Forms, VB. I have searched the web for the correct answer to this
Im trying to translate an object without using glTranslate(). I have searched through web
i have searched the web relentlessly for this and have not found anything -
I have searched the web for the answer and saw that mostly variables are

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.