| | |
PHP Not Detecting Local Files
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Feb 2009
Posts: 17
Reputation:
Solved Threads: 0
Hi, I am having a problem forcing a download from PHP. I am running 5.2 Stable. I have followed numerous tutorials and still can't figure it out. What I'm trying to do is force-download a file I made, because the browser likes opening it up inside, but it won't let me use relevant paths so I have to type in the full web address every time. Here's my working and not working code:
Working:
Not working, but want to work:
With the not working code section, it says that it can't find the file. The reason I want that section working is because I want the file size to be correct when you download (so it doesn't say "Unknown Time Remaining") and to simplify the code a little bit. Thanks for your help.
If you need me to clarify anything, just ask. I could also map my HDD and upload my IIS settings too.
Working:
PHP Syntax (Toggle Plain Text)
if ($checkbox) { $file = 'http://12.148.233.90/downloads/Tutorial1.wmv.zip'; // Set headers header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=Tutorial1.wmv.zip"); header("Content-Type: application/zip"); header("Content-Transfer-Encoding: binary"); //header("Content-Length: " . filesize($file)); ob_clean(); flush(); readfile("$file"); exit; } else { ... }
PHP Syntax (Toggle Plain Text)
if ($checkbox) { $file = 'downloads/Tutorial1.wmv.zip'; // Set headers header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=Tutorial1.wmv.zip"); header("Content-Type: application/zip"); header("Content-Transfer-Encoding: binary"); header("Content-Length: " . filesize($file)); ob_clean(); flush(); readfile("$file"); exit; } else { ... }
If you need me to clarify anything, just ask. I could also map my HDD and upload my IIS settings too.
php Syntax (Toggle Plain Text)
if ($checkbox) { $file = 'downloads/Tutorial1.wmv.zip'; // Set headers header("Cache-Control: public ;"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=Tutorial1.wmv.zip"); header("Content-Type: application/zip"); header("Content-Transfer-Encoding: binary"); header("Content-Length: " . filesize($file) ."; ");
Last edited by almostbob; Aug 13th, 2009 at 11:43 pm.
Failure is not an option It's included free, you don't have to do anything to get it
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it
Please mark solved problems, solved
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it
Please mark solved problems, solved
me too had the same problem but I gave full path.
Try giving path from a variable preceded by
Hope this will work for you.
(thought your plan was to use same code in local and remote servers).
Try giving path from a variable preceded by
$_SERVER['SERVER_NAME']; thus by making full path?Hope this will work for you.
(thought your plan was to use same code in local and remote servers).
•
•
Join Date: Feb 2009
Posts: 17
Reputation:
Solved Threads: 0
$_SERVER['SERVER_NAME'] returned a strange response; the server created a new zip file when I used that in the path, sent it over to me, and then deleted it ( ). I know the file exists, and I echo'd the
I'm getting a little confused on how
And the reason I'm using this code for zip files is one of two things, I will be force downloading other files than zip (like wmv and txt, most browsers read them) and my firefox somehow has the power to open up zip files within itself and it won't let me download them.
php Syntax (Toggle Plain Text)
$file = $_SERVER['SERVER_NAME'] . '/downloads/Tutorial1.wmv.zip';
$_SERVER['SERVER_NAME'] and that came out correct. That's not a big problem because I can just type the full address like I did before and it works (the same thing that my first code snippet does), what I want is the file size to work most of all, so people aren't left not knowing how big the file is (and these are big files).I'm getting a little confused on how
$file = $_SERVER['SERVER_NAME'] . '/downloads/Tutorial1.wmv.zip'; is different from '12.148.233.90/downloads/Tutorial1.wmv.zip' when they return the same thing. Thanks for your help.And the reason I'm using this code for zip files is one of two things, I will be force downloading other files than zip (like wmv and txt, most browsers read them) and my firefox somehow has the power to open up zip files within itself and it won't let me download them.
•
•
Join Date: Feb 2009
Posts: 17
Reputation:
Solved Threads: 0
I think it must be something wrong with the config file, it works fine under my PHP 4 Linux server. The php.ini file is available at http://12.148.233.90/php.ini if you want to take a look. I'll be going through it myself, all 1338 lines, sigh. Thanks for the help.
![]() |
Similar Threads
- can we download files from other websites using php (PHP)
- Google and PHP (Search Engine Optimization)
- testing php (PHP)
- storing details as html doc using php (PHP)
- generating txt using php (PHP)
- IE won't open *local* PHP files anymore! (Web Browsers)
- Problem in Regards to Local Files- Please Help ASAP. (Windows NT / 2000 / XP)
- Php-nuke and MySQL trouble (PHP)
- How do I open .mif files with PHP (PHP)
Other Threads in the PHP Forum
- Previous Thread: Conditional file upload issue
- Next Thread: php parse error - Please help me
Views: 431 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email error errors file files folder form forms function functions google href htaccess html if...loop image include insert integration ip java javascript joomla jquery limit link login loop mail menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion recursive regex remote script search select server sessions shot sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable vbulletin video web xml youtube






