Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is this possible with PHP?

Status
Not open for further replies.

sd0t1

IS-IT--Management
Mar 14, 2007
131
US
Is it possible to play a file that's located outside your web server on another server by generating links to the file location? File type is .asf.


Example: if the path is (hostname is computer1) "C:/hearings/2011/April/14th/hearing.asf".

How do I allow this file to be accessed and downloaded from the intranet by any user that has permission to access the share that houses the .asf files?

Can I create links like the one below that will allow the file to be downloaded?
<a href='//computer1/hearings/2011/April/14th/hearing.asf'>click here</a>

Thanks for any input you guys have.
 
Jpadie, how are you pal.

I thought it should be possible, however I couldn't make it work. I think I figured it out though.

Do I have to put any files that i want a user to be able to download on a directory inside a web root? In my testing, that's the only way I can make this work.
My intranet is of course a web server. However my actual files that I want my users to be able to download are on a file server on the network somewhere.
I can only access the files on my file server if I install Apache and turn it into a web server.

When I do this, all works fine. Although I would like to not have to run two web servers, but my fear is that's just the only way to serve files on a server is via web server.

Am I right?
 
so long as the uri is absolute or relative to the client, the // notation should work. you can always make it explicit by prefixing the uri with file://

alternatively you can do it all with your webserver. for this to work you would supply the link like this
Code:
[URL unfurl="true"]http://path/to/documentServer.php?documentID=efregre[/URL]

then in your documentServer.php script you would use the $_GET['documentID'] value to look up the location of the actual resource, set the appropriate headers and then use readfile to send the contents of the file to the client.
 
I understand and I got it all working. It's actually pretty slick. I didn't do the file:// notation to make it explicit, but I'm about to go back and change that as it seems like a good idea.

All this brings me to another problem and question. I always have trouble with download scripts, I can make them work, but getting the file to play once it's downloaded. I eventually started finding download scripts on the web, and I still have trouble playing/viewing the downloaded file.

For this project, I used a download script i found on a website called tutorial chip dot com/ php-download-file-script and I still get a corrupted file.
Right now the original file and the downloaded file are both on my laptop and my script is just reading and indexing the files. Then allowing a user to search and serve them up.
However the original .asf file plays in media player just fine, but the downloaded file isn't supported.

What could be causing this? Any ideas?
 
the main reasons for corruption are incorrect headers or corrupting the content with extra spaces.
basic logic is this

1. determine whether the file exists on your server ($fileName)
2. determine the mime type of the file ($mimeType);
3. determine the size of the file ($fileSize)
4. send the headers

Code:
<?php
//get some information
$fileURL = getFileURL( $_GET['fileID'] ); //this is the lookup
//check exists
if( !file_exists( $fileURL ) || !is_file( $fileURL ) ) die('No such file');
$mimeType = mime_content_type( $fileURL );
$fileSize = filesize( $fileURL );

//send the right headers
header('content-type:' . $mimeType);
header('content-dispositon: attachment; filename:"' . $fileName . '"');
header("content-transfer-encoding: binary"); 
header("content-length: " . $fileSize); 
?>

then send the actual content and explicitly exit to avoid corruption of the binary.

Code:
@readfile($fileURL); 
exit;
 
Great information as usual. From your example it sparked me to just go back and relearn about requesting pages and I found a great article that I would recommend to anyone trying to figure out how all that works.
Here is the link, apptools.com/phptools/force-download.php.

I finally have a better understanding and a working download script.
We can consider this issue closed. I'll post my new issue on a new thread.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top