close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Download works locally but not on remote server.

Thread began 8/18/2009 12:57 pm by John Langer | Last modified 8/25/2009 1:52 pm by Eric Mittman | 2746 views | 8 replies |

John LangerBeta Tester

Download works locally but not on remote server.

I've developed a page on a church website to listen to and download mp3 files as well as read and download text and pdf files.

On my testing server on my PC (Vista) (WAMPSERVER2) it all works brilliantly, even though I say so myself. I can play the mp3 files, see the pdf and txt files in the browser (by clicking on the linked text) and by clicking the download button the files are offered for download by the browser (FF3 and IE8).

I have now uploaded all the files to the server and it's gone a bit pear shaped.

I've made sure that all the dependant files are uploaded as well.

The mp3's play fine.

By opening the TXT and PDF files in the browser window (clicking on the linked text) the files open fine to be read in the browser.

The download buttons however just open up another browser window and in the case of PDF and MP3 display "rubbish" and in the case of the txt file it displays unformatted text. It should offer the files for download.

I've used DigitalFilePro2 for this.

As it works locally but not in the remote browser I've asked the hosting people in case it's just a setting in the php.ini file, or some other setting.

Can it be something to do with DFP2 or is it more likely the web server? If so, any ideas what?

Here's the page again

Sign in to reply to this post

John LangerBeta Tester

Well the hosts are saying everything should work OK. We have played the MP3's directly from their location on the server so it must be something to do with the code.

Any help would be appreciated.

Sign in to reply to this post

Eric Mittman

I have done a bit of digging on this and the Digital File Pro code should force the download of the file. It is very similar to the code examples on php.net for this type of download. In my testing and searching I found some other code that may help in the download process. I have made an example script for this code so that you can do a test.

In this example you will need to fill in a file name and the file system path to that file. Place this code on a new page then after you fill in the values correctly load it to your live server and test it out. Let us know what the result is.

php:
<?php

$fileName 
""//the name of the file, example: yourfile.pdf
$path "" $fileName//the file system path to the file, example: C:\\Inetpub\\wwwroot\\

header('Cache-Control:');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' $fileName '"');

//these next four lines are not in the DFP code
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
//down to here

header("Content-length: ".filesize($path));

//these next two lines are not in the DFP code also
ob_clean();
flush();
// to here

readfile("$path");
?>
Sign in to reply to this post

John LangerBeta Tester

Hi Eric,

Firstly, many thanks for your help on this.

I've done as you ask and the result, unfortunately, is the same.

This is the adapted code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Download test</title>
</head>

<body>
<?php
$fileName = "wemmicks.pdf"; //the name of the file, example: yourfile.pdf
$path = "http://billericaybaptist.net/av-files/sermon-attachments/" . $fileName; //the file system path to the file, example: C:\\Inetpub\\wwwroot\\

header('Cache-Control:');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $fileName . '"');

//these next four lines are not in the DFP code
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
//down to here

header("Content-length: ".filesize($path));

//these next two lines are not in the DFP code also
ob_clean();
flush();
// to here

readfile("$path");
?>
</body>
</html>



And this is the link to the actual page

Sign in to reply to this post

Eric Mittman

Darn, I thought we might have something with this. There is one thing that I noticed about the values you filled in for the path you have this:

sermon-attachments/

Do you know the server file system path to this location, the way the script is setup it is expecting a file system path and not a URL to this location. If you do not know the file system path attached to this post is a php script that will tell you where it is at when you run the page. You should put this page inside of your sermon-attachments directory and run it to obtain the correct file system path. Once you have this please plug it in to the download test script to see if you have a better result. Please let us know what you experience.

I have asked around to see if anyone has seen this type of thing or know of what may be responsible and since you can view the files directly in the browser it seems that it may be a php setting that is causing this. I'm not sure what setting may be responsible for this but perhaps safe more or some other setting that would interfere with sending headers to the browser.

Attached Files
realpath.zip
Sign in to reply to this post

John LangerBeta Tester

Hi Eric,

Frustrating isn't it! :)

Ok I have altered the path to /home/billeric/public_html/av-files/sermon-attachments/

Still no luck I'm afraid.

This is the link to phpinfo perhaps you could get someone to look at that? Just an idea. As I said, I did ask the hosting providers to take a look at all that stuff and they said that they couldn't see anything obvious but the guy did say that he wasn't a PHP expert so maybe there is something. I can't see how it can be anything else really.

Thanks for your continued support on this.

Sign in to reply to this post

John LangerBeta Tester

Hi,

Still no joy with this. I've had to resort to telling them to just right click the link and "Save link as..." etc.

Meanwhile the hosts have been looking at it and today said this:
"I've been working on this for most of the day and am unable to find the problem. It seems this is a common problem when using readfile to open a binary file such as PDF or MP3. I have also tried reverting to Apache and the problem still exists, ruling out a problem with Litespeed." (they are using litespeed instead of apache but as you can see even when they reverted to Apache it still didn't work)

Does "common problem when using readfile to open a binary file such as PDF or MP3" mean anything to you?

Your help is really appreciated with this.

Sign in to reply to this post

John LangerBeta Tester

Solved!

Hi,

You'll be pleased to know that I've got it working. I think it's worth an explanation so here goes:

Originally the download behaviour was completely on the same page as the buttons that called the behaviour. I then thought about another site on the same server that had a similar download behaviour that worked! The difference was the fact that clicking the download button sent it to another page where the behaviour took place. When I tried to replicate that I had no joy and almost gave up but I then thought that I was using the site template to make the (new) page and then adding the behaviour.

So I tried it again but this time I just made a blank PHP page and only added the behaviours necessary (recordset and DFP). And it worked!

So it seems to me that the problem lay in just too much going on on one page. My template page really is a very busy thing.

See for yourself sermons_Detail.php?sermonID=125

So once again my apologies for all this but I really, really do appreciate the fact that you did try to help.

Many thanks,

John

Sign in to reply to this post

Eric Mittman

That is terrific that you were able to track this down and find the solution. I still find it very confusing as to why it was not already working but if having it on another page makes it work that is great, hopefully someone else who is getting frustrated with the same problem will be able to make use of your technique. Thanks for posting back after you found the solution.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...