简体   繁体   中英

Download Zip files in PHP

My wesite has a login feature for users. The users are the users who attended a training session at my training facility. Now the training session is named in numbers , eg 2655, 2755 etc. Now i have some particular files or the session kit you can say to be available to the user to download from his login, but only he should be able to download the files of his session. Now i have files in zip. so i have a variable in php name $sessionno which is also the same name of the file which the user has to download. so my following thing does'nt work.

<a href = " <?php header ('location : $sessionno.zip'); ?> download </a>

so this does'nt work , any ideas ?

header isn't what you are looking for when trying to add a path to a href attribute on an anchor. For your specific example you would want to use echo which outputs the string you want to the page.

<a href="<?php echo "$sessionno.zip"; ?> download </a>

Alternatively, you could also use PHP Short Tags (eg. <?="$sessionno.zip" ?> ) which is identical to calling echo the way my first example shows. Short tags can make the code a little cleaner but not environments will have the configuration enabled.

For future reference, you would use header when you want to send specific HTTP headers to the client. The specific header you were trying to pass is a valid header, just used in an incorrect way. You would use that header if you want the current request to tell the client that you want them to navigate to the URL you specified.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM