473,394 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

fopen() and fpassthru() limited file to under 4kb

I have written a script to download a file from a website. But it only download about 700bytes --- less than 4kb. What am I doing wrong?

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // block any attempt to the filesystem
  3. if (isset($_GET['file']) && basename($_GET['file']) == $_GET['file']) {
  4. $filename = $_GET['file'];
  5. } else {
  6. $filename = NULL;
  7. $err = "<p>Sorry, the file you are requesting is unavailable.</p>"; 
  8. if (!$filename) {
  9. // if variable $filename is NULL or false display the message
  10. echo $err;
  11. } else {
  12. $path = 'downloads/'.$filename;
  13. if (file_exists($path) && is_readable($path)) {
  14. // get the file size and send the http headers
  15. $size = filesize($path);
  16. header('Content-Type: application/octet-stream');
  17. header('Content-Length: '.$size);
  18. header('Content-Disposition: attachment; filename='.$filename);
  19. header('Content-Transfer-Encoding: binary');
  20. // open the file in binary read-only mode
  21. // display the error messages if the file can´t be opened
  22. $file = fopen($path, ‘rb’);
  23. if ($file) {
  24. // stream the file and exit the script when complete
  25. fpassthru($file);
  26. exit;
  27. } else {
  28. echo $err;
  29. }
  30. } else {
  31. echo $err;
  32. }
  33. }
  34. ?>
  35.  
Aug 12 '10 #1
1 1583
johny10151981
1,059 1GB
You can follow the link
Aug 13 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Steve | last post by:
hello all im looking to make a download script as i cannot use the .htaccess to control directory access to files as im using a php login system using mysql and sessions. i have been playing...
6
by: moonriver | last post by:
I write a program accessing files in network drive o:. It is doable as a standalone application. However, if it is running under windows service, the following exception will appear: 13/07/2004...
2
by: Cindy Liu | last post by:
Hi, If my xml resource file is directly under my project file, I have no problem to load that xml file via Assembly.GetManifestResourceStream. However, after I create a folder under the project...
33
by: jacob navia | last post by:
Recently there was a discussion in this group about how to retrieve the file name given a FILE *. The question raised my curiosity, and after some research I have come up with a good...
4
by: CrazyDog | last post by:
I download a project from a source code web,the author saied that it's created under VC++6.0,and the project contain lots of *.cc file(I think they are same as the *.cpp file), but when i build it...
0
by: Guy Lateur | last post by:
Hi all, I'm working on an application that will be used by several users at the same time. The user should be able to both read and write to some data file stored on our file server. My question...
4
by: Stephen Kay | last post by:
Maybe I don't understand how to use this yet, but I was using (example): $html = implode('', file('http://www.mysite.com/transbar.html')); echo $html; This works. But if I try it on a...
5
by: sangith | last post by:
Hi, I have a file which is in the following format: This file is classify.txt #######Alphabets######### . . . #######Numbers##########
3
by: Sport Girl | last post by:
Hi everybody, please can somebody help me about how to write the script to export oracle database specific tables into a dump file under windowws thank you please it is urgent
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.