troubleshooting Question

How to serve a rackspace file, but force "Save As..."?

Avatar of DrDamnit
DrDamnitFlag for United States of America asked on
PHP
18 Comments1 Solution244 ViewsLast Modified:
I have some files living at Rackspace. To avoid filename collision, they are all renamed to an md5 hash of microtime(true), and the original file name is saved in the database.

When a user is to download one of these files, I need to:
1. serve the file straight from rackspace (they are huge).
2. Have the file pre-renamed back to the original file name so that when the user downloads it, it is transparent.

I have tried this:
			/* Extract information from Rackspace */

			$headers=get_headers($file_path);
			$buffer = explode(":", $headers[4]);
			$content_length = trim($buffer[1]);
			$buffer = explode(":", $buffer[7]);
			$content_type = trim($buffer[1]);

			$resource = fopen($file_path,'rb');

			/* Resend to user */
			http_send_content_disposition($filename,true);
			http_send_content_type($content_type);
			// http_send_file($file_path);
			http_send_stream($resource);

but it comes back with "File not found". However, when I do header("Location: $file_path") I get the files perfectly. (They are just named the hash, which is not nice ot the user).

What am I missing here?
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 18 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 18 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros