help in header(); function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
trazan
Forum Newbie
Posts: 15
Joined: Fri Nov 13, 2009 8:41 pm

help in header(); function

Post by trazan »

hello everyone
i use header() function to make a download page to hidden the link from the visitor
when i use it only in the page it workes perefect and the download support resume
but when i use it in a page but before it some MySql queries & starting a Session it work but the downlaod dosen't support resume
i just need to know how i can make the download in the second page support resume and how i can control in ( support resume ) cuz maybe i want to stop it for some members
thanks alot
User avatar
BlaineSch
Forum Commoner
Posts: 28
Joined: Sun Jun 07, 2009 4:28 pm
Location: Trapped in my own little world.

Re: help in header(); function

Post by BlaineSch »

You want to stop it for some members? I'm not really sure what your saying here. If your using a database you can simple add another column 'enabled' to see if they are allowed to download etc. Once the download has started I do not believe it's possible to stop the download.

If I got this wrong can you show us your source?
trazan
Forum Newbie
Posts: 15
Joined: Fri Nov 13, 2009 8:41 pm

Re: help in header(); function

Post by trazan »

sorry cuzmy english not perfect
i alerady mad a colum ( resume) if it's value=1 the download will support resume , if it's value=2 the download will not support resume
i just want to know how can i make the download support resume cuz when i put the functon [ header() ] in the midell of the page the download wasn't support resume i think the Session function is the reason, am i right?
User avatar
iankent
Forum Contributor
Posts: 333
Joined: Mon Nov 16, 2009 4:23 pm
Location: Wales, United Kingdom

Re: help in header(); function

Post by iankent »

Send the header 'Accept-Ranges:', e.g.

to enable resuming downloads:

Code: Select all

header('Accept-Ranges: bytes');
and to disable resuming downloads:

Code: Select all

header('Accept-Ranges: none');
unfortunately, thats only an instruction to the downloader, and may not guarantee that the download wont attempt to resume anyway.

The next thing you need to do is take notice of the $_SERVER['HTTP_RANGE'] variable. Easiest to have a look at an example:
http://stackoverflow.com/questions/1573 ... d-the-file

hth
trazan
Forum Newbie
Posts: 15
Joined: Fri Nov 13, 2009 8:41 pm

Re: help in header(); function

Post by trazan »

thanks (iankent) i am already use this code but i found the problame at least
when i receive the file path from database like the

Code: Select all

       $id=$_POST['id'];
        $getf="SELECT * from filez where id='$id'";
 
        $getf2=mysql_query($getf) or die("This Is Worng Fils Or It Has Been Deleted");
 
        $getf3=mysql_fetch_array($getf2);
    $filepath=$getf3[path];
or put the path in a Session like this

Code: Select all

    $_SESSION['filepath']  = $getf3[path];
the download will not resume
but if i directly put the pat in a avriable like this

Code: Select all

   $filepath = 'file.zip';
the download will resume
i don't know why this is happening and i am looking for ur help please
User avatar
iankent
Forum Contributor
Posts: 333
Joined: Mon Nov 16, 2009 4:23 pm
Location: Wales, United Kingdom

Re: help in header(); function

Post by iankent »

trazan wrote:the download will resume
i don't know why this is happening and i am looking for ur help please
If the only difference is that you're outputting the filename from a database instead of it being hardcoded that shouldn't make any difference to how the script works.

Have you checked you're not outputting any whitespace that could be affecting things? Maybe easier to leave the closing ?> bracket off the end and make sure the opening <? is right at the start so no spaces can be accidentally output.

If that doesn't help, and apart from retrieving the filename the script is identical every time, try var_dump'ing the filename in the different circumstances to see if there's a problem with the file names

very odd!
trazan
Forum Newbie
Posts: 15
Joined: Fri Nov 13, 2009 8:41 pm

Re: help in header(); function

Post by trazan »

there is no whitespace in the filepath in the database
and the download is done correctly but why there are no resume
:banghead: :banghead: :banghead: :banghead:
trazan
Forum Newbie
Posts: 15
Joined: Fri Nov 13, 2009 8:41 pm

Re: help in header(); function

Post by trazan »

i wating ur help
User avatar
iankent
Forum Contributor
Posts: 333
Joined: Mon Nov 16, 2009 4:23 pm
Location: Wales, United Kingdom

Re: help in header(); function

Post by iankent »

Did you look at the link I sent you? It explains how to enable resumable downloads using PHP.

Even if Apache is configured to give you resumable downloads, if it believes for any reason that the file won't be the same next time its accessed, it may not give the client the option of resuming to prevent data corruption. In this case, you'll need the manually write the resuming code yourself
Post Reply