Link to home
Start Free TrialLog in
Avatar of Richard Korts
Richard KortsFlag for United States of America

asked on

Download files does not work

This question is an extension of

The Expert who was helping me with this has become unresponsive.

In essence, when I rent the attached php script in a sub folder one level down from public_html, it does not work.

If I run it at the root (public_html) it works perfectly.

Why is that?


Avatar of Cyril Joudieh
Cyril Joudieh
Flag of Lebanon image

Most probably, the folder does not have enough privileges for the internet user to create a zip file.

I would check the privileges of the folder or if the file already exists and can't be replaced.
Avatar of Richard Korts



The zip file get's created. I can run a test & it's there.

The folder permission on the sub folder (called dev) is 755. The zip file is created in a subfolder of dev called zips. The permission on that folder is 755.

Everything is perfect, it just won't download.

Thank you
Does the $path contain the correct path to the zip before reading it?
Add a test to it:

if (file_exists($path )) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="'.basename($path ).'"');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($path ));
    readfile($path );

Open in new window

See readfile().
Notice the $output = ob_get_clean();

The file debug.log contains several such test, this was what was one yesterday:

OUTPUT: nf = 4 
file = doc_files/LS-912-eTCX-IOM-11-2019.pdf 
file = doc_files/184853_eTCX_0610_EFS_208v.pdf 
file = doc_files/LS-910_eTCX_System_Brochure.pdf 
file = ../pselsumms/46619summarynl.pdf 
fn = 46619summarynl.pdf 
path = zips/

Open in new window

The folder zips is there, dev/zips
What is the exact path to the doc_files/ folder?
Is this folder in the same folder as the calling script or is it one level up?

Can you post a map of what your folder structure looks like showing doc_files/ zip and calling script.
Folder structure like this:
public_html is the root & contains the live system, which has all the same folders as the "development" system, in the folder dev.

Within dev are doc_files, zips, temp as well as copies of everything in public_html.

One or two of the files to be downloaded are in a folder one level up from dev, pselsumms.They are the files on lines 28 - 30.

attached shows the folder structure (partial) in dev.

dev folder structure.PNG
If that is the path the script runs from then I don't see a zips folder?

In the code on line 15 we have this
$path = "zips/" . $zipname;

Open in new window

Which implies there should be a zips folder in the script root (the folder that contains the folder download_simple.php )

Also can you post a sample of what will be sent to

Open in new window


I tried to do as you said. Not the download_simple.php script will NOT run. I've tried everything I can think of, it does NOTHING. I have run it through the php syntax checker, I put a javascript alert into the call, nothing.

This is now of course on top of the other issue.

Here is the reference from the calling program:

if (x == "d") {
         alert("got to download_simple.php ref");
         dest = "" + str;

         window.location = dest;

      } else {
 = "email_docs.php?files=" + str + "&memail=" + + "&orem=" + + "&comments=" +;

         return true;
Since it displays the alert, it reaches (or tries to) download_simple.php, but it does not run. The zip file is NOT created and the ob file (debug.log) is empty.

Here is the source from download_simple right now. Can you suggest something I can do see what's going on INSIDE download_simple.php?


All this worked on Nov. 8, I recreated debug.log this AM so I could show you iyts contents with JUST one try.

Thank you

The ob_get_clean () function returns the contents of the output buffer and then deletes the contents from the buffer.
Seems like you're killing your output buffer. Why? Consider, the may be not send at that moment.

That would explain it COMPLETELY except for two minor issues. An earlier respondent(to the initial question) said use ob_get_clean.

(1) When I run the EXACT script from the root (public_html), it works fine.

(2) And now, it won't even execute the code at ALL for some other unknown reason (just started an hour ago). See my response to Julian.

So I should just do ob_get?

This nightmare keeps getting worse with the other (I think) unrelated problem.

To proceed I need to understand what this is meant to do.
I am assuming you are getting data in this form

Open in new window

You are specifically excluding
$file != 'doc_files/';

Open in new window

Which does not make sense as this is going to find files called doc_files/ which is odd - is this mean to exclude files in that folder?
There is another check for 'doc_files on line 22 - again testing the full name against the folder and again on line 25

On line 26 if it IS a doc_file you add the file as is
On line 29 you take the filename from the 13th character onwards implying the filenames have a certain format.

I did get this to work (sort of) but I need to know what the incoming data looks like and what the structure of the site is in terms of where it is getting the source files from.

I also need to understand the 'doc_files' references - what is the intention there.


Here is a string passed to download_simple.php (one example):

str = doc_files/LS-912-eTCX-IOM-11-2019.pdf~doc_files/LS-910_eTCX_System_Brochure.pdf~doc_files/LS-911_eTCX_Sample_Spec.doc~../pselsumms/46639summarynl.pdf

I just used the ~ delimiter as I knew it would NEVER bein any of the file names I was working with.

The first 3 are fixed document files (mostly pdf's) in the doc_files folder. The last one is a summary of the configuration (what this app does). It is located one level above the folder dev, thus in ../pselsumms/. This file is unique, the number 46639 always increments by 1 for every new configuration.

I believe I had the code to eliminate file "doc_files/" because I thought that would be a file returned (potentially) in the query string (just the folder name, no file after the /). In this example, there is none. Not sure why I did that but it doesn't hurt.

So the code is supposed to copy the file 46639summarynl.pdf from ../pselsumms/ to the temp folder from hence it is zipped with the others.

There is now a new issue that started yesterday. Before yesterday, The zip file was created in the zips folder and the debug.log file contained the content of the echo messages. Yesterday, I put the echo line in as line 4 in the attached (current version), then when it stopped working I commented it out.

Now latest_download_simple.php does nothing.


Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

Thanks for all your work, I think I've been barking up the wrong tree (an American euphuism) for at least a week,

The issue is partially that I misunderstood the HTML <button> element, I did not realize that it acted like a submit button so I had created about 200 lines of Javascript to deal with that. So I've cleared that up (I think), but now I cant get anywhere because there are errors in my remaining JS that Chrome debugger finds but has them badly mislabeled as to where they are & I can't see the critical one, so I'm putting another EE question on that issue, I think I'm missing the obvious, but you know how it is, I wrote that code and stared at it 20 times and CANNOT see the problem. Another set of eyes will undoubtedly find it.

We frequently bark up the wrong tree in this part of the world as well, and for the second issue - that is why we have rubber ducks in coding, all developers go through periods of myopia after staring at their code for too long..

If you open another question post the link here so we can find it.

I'm going to set up an account for you so you can log in & run though a test to get there.

I'll get that to you