ArielZusya Posted March 2, 2008 Share Posted March 2, 2008 I'm very new to php (literally hours *GRIN*). I've got a link on a page that I'd like to point to a php page and pass some variables to that page. Here's what I'm trying to do. I've got a list of files on my site that I'd like a user, when clicking on an associated link, to be forced to download the file rather than open it. I'm trying to prevent streaming. Some of the files are midi, some are pdf, some are finale .mus files, and some are mp3s. Right now I have the link on the list point to a php file unique to the spcific link (in other words if the link is for file1.mid then the link points to file1_mid.php). I'd like to able to pass the filename and the mime-type to a more universal php file and have it work for all the files which could be downloaded (in other words, something like sendmethefile.php?myfn=file1.mid&mymt=audio/midi). This is, I'm certain, sounding more complex than it actually is (yep... I'm that new at this... can't even figure out how to describe it simply). Here's the code I've got so far: First, an example of the individual page referenced above (file1_mid.php): <?php header('Content-disposition: attachment; filename=file1.mid'); header('Content-type: audio/midi'); readfile('file1.mid'); ?> and this works just fine but I'd like it to be one size fits all... so something like (sendmethefile.php): <?php $myvar1 = $_GET['myfn']; $myvar2 = $_GET['mymt']; header('Content-disposition: attachment; filename=' && $myvar1); header('Content-type: ' && $myvar2); readfile($myvar1); ?> but that doesn't work. I get the following error: Warning: readfile(file1.mid): failed to open stream: No such file or directory in /<actual directory info has been removed>/sendmethefile.php on line 6 It would be great if I could send the filename and mime-type so I can use the same sendmethefile.php for all the various files I would have links to on my site. What do I need to do differently? Thanks for your help! Link to comment https://forums.phpfreaks.com/topic/94082-n00b-question-struggling-with-passing-variables-to-a-php-page/ Share on other sites More sharing options...
dual_alliance Posted March 2, 2008 Share Posted March 2, 2008 <?php $myvar1 = $_GET['myfn']; $myvar2 = $_GET['mymt']; header('Content-disposition: attachment; filename=' && $myvar1); header('Content-type: ' && $myvar2); readfile($myvar1); ?> I'm not sure why you are using the operator && (and) in the header function, you will probably have more luck with the code below <?php $myvar1 = $_GET['myfn']; $myvar2 = $_GET['mymt']; header('Content-disposition: attachment; filename='.$myvar1); header('Content-type: '.$myvar2); readfile($myvar1); ?> Link to comment https://forums.phpfreaks.com/topic/94082-n00b-question-struggling-with-passing-variables-to-a-php-page/#findComment-481957 Share on other sites More sharing options...
ArielZusya Posted March 2, 2008 Author Share Posted March 2, 2008 well... I'll tell you why I was using the && operator... bacause until now I didn't know any better. Your solution worked like a charm. Thank you so much! Link to comment https://forums.phpfreaks.com/topic/94082-n00b-question-struggling-with-passing-variables-to-a-php-page/#findComment-481958 Share on other sites More sharing options...
dual_alliance Posted March 2, 2008 Share Posted March 2, 2008 Guess that is a good reason to use it then . No problem Link to comment https://forums.phpfreaks.com/topic/94082-n00b-question-struggling-with-passing-variables-to-a-php-page/#findComment-481959 Share on other sites More sharing options...
phpSensei Posted March 2, 2008 Share Posted March 2, 2008 The && (and) operator wont join two strings together or vars for that matter. "." the dot glues the strings, or vars, or mixed together. A AND operator would be used in a if/else statement like if(($i > 3) && ($i < 10)){ echo 'i is:' .$i; } Link to comment https://forums.phpfreaks.com/topic/94082-n00b-question-struggling-with-passing-variables-to-a-php-page/#findComment-481960 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.