JavaScript and client side scripting.
Moderator: General Moderators
LiveFree
Forum Contributor
Posts: 258 Joined: Tue Dec 06, 2005 5:34 pm
Location: W-Town
Post
by LiveFree » Fri Feb 03, 2006 2:43 pm
Hello!
I have a PHP script that gets all the Downloads from one catagory. But I need to have the filename for each file clicable and when it is clicked, that file downloads.
Thanks
I dont really think this can be done w/ PHP
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Fri Feb 03, 2006 2:49 pm
what kind of file are you trying to download? Most files (that can't be opened in a browser) just require a link to them.
take a look at
header() too...
LiveFree
Forum Contributor
Posts: 258 Joined: Tue Dec 06, 2005 5:34 pm
Location: W-Town
Post
by LiveFree » Fri Feb 03, 2006 2:54 pm
They are mostly movie files...
Wouldnt I need JS? Or is there some click functions that executes a specific function (in my case, to force a DL) in PHP I dont know of
josh
DevNet Master
Posts: 4872 Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida
Post
by josh » Fri Feb 03, 2006 2:57 pm
Code: Select all
// force to download a file
$file = "http://localhost/test/".$_GET['file']."";
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header( "Content-Disposition: attachment; filename=".basename($file));
header( "Content-Description: File Transfer");
@readfile($file);
LiveFree
Forum Contributor
Posts: 258 Joined: Tue Dec 06, 2005 5:34 pm
Location: W-Town
Post
by LiveFree » Fri Feb 03, 2006 2:59 pm
Yea,
Ill put that into a function, but I need a little snippet where (remember this is in a while loop from every DB row) when a user clicks on a link (NOT A BUTTON), the file is downloaded.
Like I said, I think its JS
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Fri Feb 03, 2006 3:00 pm
no the code jshpro2 posted would be your target page, you'll need to fetch file info based on what link is clicked then send the file down.
if they are movie files you should just be able to link to the file itself though
LiveFree
Forum Contributor
Posts: 258 Joined: Tue Dec 06, 2005 5:34 pm
Location: W-Town
Post
by LiveFree » Fri Feb 03, 2006 3:02 pm
Oh Damnit
Thanks Guys
/me Kicks myself for not seeing that
My experiance has betryared me
josh
DevNet Master
Posts: 4872 Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida
Post
by josh » Fri Feb 03, 2006 3:05 pm
I must mention if you are going to use the code I posted you need to make sure $file is not your database connection script or something confidential
LiveFree
Forum Contributor
Posts: 258 Joined: Tue Dec 06, 2005 5:34 pm
Location: W-Town
Post
by LiveFree » Sat Feb 04, 2006 5:58 pm
Okay,
I have made it work ... so so
Code: Select all
<?php
session_start();
// force to download a file
$source=$_SESSION['file'];
$file = "videos/$source";
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header( "Content-Disposition: attachment; filename=$file");
header( "Content-Description: File Transfer");
@readfile($file);
?>
When you click on the download link, the file name is always like so: video-filename.jpg
NOTE** It does actually put in the right filename, just the video- part is stuck on
Thanks for teh code though