Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Web Coding › need Help writing html download link for media
New Posts  All Forums:Forum Nav:

need Help writing html download link for media

post #1 of 6
Thread Starter 
I am building a website for some of my art and personal indie films and phone videos etc. I have forgot so much about html since college. on my site I have been using this general format as a base for my download links
Code:
<p>Example, 2012, xxxMB   <a href="movies/Example.zip">Download Here</a><a href="movies/Example.zip"><img src="movies/example.jpg" alt="some_text"></a></p>
the problem I'm having is i would rather not have to zip all of my content, as i don't like having to double the amount of disk space i need to have both the extracted and zipped copy's of both files, however when i try to do it with this format it tries to stream:
Code:
<p>Example, 2012, xxxMB   <a href="movies/Example.mp4">Download Here</a><a href="movies/Example.mp4"><img src="movies/example.jpg" alt="some_text"></a></p>
so what would i do to have a direct download of the media without having to zip and unzip it everytime its added or downloaded?
post #2 of 6
Code:
<p>To Download this file, Right-Click on a link and then select Save Link As</p>
Core I7
(13 items)
 
  
CPUMotherboardGraphicsRAM
I7 920 rev. D0 @ 4.26Ghz EVGA X58 SLI EVGA GTX 285 OCZ XMP 3x2Gb (pc3 12800) 
Hard DriveOptical DriveOSMonitor
Western Digital Caviar Black 640Gb x 2 LG GH22LS30 openSuse 12.1 x64 HP F2105 
PowerCase
CORSAIR 850TX Cooler Master ATCS 840 
  hide details  
Reply
Core I7
(13 items)
 
  
CPUMotherboardGraphicsRAM
I7 920 rev. D0 @ 4.26Ghz EVGA X58 SLI EVGA GTX 285 OCZ XMP 3x2Gb (pc3 12800) 
Hard DriveOptical DriveOSMonitor
Western Digital Caviar Black 640Gb x 2 LG GH22LS30 openSuse 12.1 x64 HP F2105 
PowerCase
CORSAIR 850TX Cooler Master ATCS 840 
  hide details  
Reply
post #3 of 6
Thread Starter 
Quote:
Originally Posted by tom.slick View Post

Code:
<p>To Download this file, Right-Click on a link and then select Save Link As</p>
no way to automate the save as into the script so all that's needed is a right click?
post #4 of 6
Quote:
Originally Posted by THC Butterz View Post

no way to automate the save as into the script so all that's needed is a right click?
Correct, with a link like that it' up to the user's browser settings (plugins) whether it streams or downloads. If for example, you use Firefox and go to your extensions and disable Quicktime player, or any other player plugin (like VLC) then it should download instead of stream.
post #5 of 6
A normal left click will download the file. If it's a text file or something, and you want to make the browser download it rather than open it - you'd have to change the headers sent from the server.

Basically, what you'd do is in your link have:
Code:
<a href="path/to/download.php?f=filename.txt" title="Download filename.txt" target="_blank">Download filename.txt</a>

Then, inside of download.php you'd have something like:
Code:
<?php
$file= $_GET['f'];

if( isset( $_GET['f'] && file_exists( $file ) )
{
   header('Pragma: public');    
   header('Expires: 0');                
   header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
   header('Cache-Control: private',false);
   header('Content-Type: application/force-download');
   header('Content-Disposition: attachment; filename="'.basename($file).'"');
   header('Content-Transfer-Encoding: binary');
   header('Connection: close');
   readfile($file);
} else {
   echo "ERROR: File not found!";
}
?>

I've not tested the above code, but you should get the idea... Also, note that there are security risks involved with this as someone could pass in a URL to download any file from your server...

Lastly, this can also be achieved with an Apache .htaccess file.

Oh, and if you're determined on have them right-click anyway... You can accomplish that with JavaScript... The easiest way would be to use the jQuery framework's [ mousedown ] method. You ought to be able to check eventData.which to determine which mouse button was pressed. I believe 1 is left, 2 is middle, and 3 is the right mouse button. You'd would then redirect the user to the file above... Actually, you may even be able to create an AJAX request to fetch the file, I'm not sure how that would play out though...
Edited by Phaaze - 12/5/12 at 7:07am
     
CPUMotherboardGraphicsGraphics
i7 2600K ASUS P8Z68 Deluxe GTX 280 - Died EVGA GeForce GTX 760 Super Clocked 
RAMHard DriveOSMonitor
2x 4GB G.SKILL PC-16000 2x Corsair Force GT 120GB (RAID-0), 3TB Hitachi DS Windows 8.1 64-bit 2x Dell U2410 
MonitorKeyboardCaseMouse
1x Dell U2415 Logitec Wireless Illuminated Keyboard (K800) Fractal Design Define R3: Silver Arrow Logitec Performance Mouse MX 
CPUMotherboardGraphicsRAM
Intel Core i7 6700K Z170MX-Gaming 5 EVGA GeForce GTX 760 Super Clocked 2x G.SKILL TridentZ Series 16GB DDR4 3200 (Blac... 
Hard DriveHard DriveCoolingOS
Samsung SSD 850 EVO 500GB 3TB Hitachi HDS723030ALA640 Phanteks Slim Low-Profile 120mm PWM CPU Cooler ... Windows 10 Professional (64-bit) 
MonitorMonitorMonitorKeyboard
2x Dell U2410 1x Dell U2415 Insignia 46" NS-46L780A12 Logitec Wireless Illuminated Keyboard (K800) 
PowerCaseMouseMouse Pad
EVGA SuperNOVA 850 G2 Corsair Carbide Series Air 240 (White) Logitec Performance Mouse MX Vipamz Extended XXXL Gaming Mouse Pad (White) 
  hide details  
Reply
     
CPUMotherboardGraphicsGraphics
i7 2600K ASUS P8Z68 Deluxe GTX 280 - Died EVGA GeForce GTX 760 Super Clocked 
RAMHard DriveOSMonitor
2x 4GB G.SKILL PC-16000 2x Corsair Force GT 120GB (RAID-0), 3TB Hitachi DS Windows 8.1 64-bit 2x Dell U2410 
MonitorKeyboardCaseMouse
1x Dell U2415 Logitec Wireless Illuminated Keyboard (K800) Fractal Design Define R3: Silver Arrow Logitec Performance Mouse MX 
CPUMotherboardGraphicsRAM
Intel Core i7 6700K Z170MX-Gaming 5 EVGA GeForce GTX 760 Super Clocked 2x G.SKILL TridentZ Series 16GB DDR4 3200 (Blac... 
Hard DriveHard DriveCoolingOS
Samsung SSD 850 EVO 500GB 3TB Hitachi HDS723030ALA640 Phanteks Slim Low-Profile 120mm PWM CPU Cooler ... Windows 10 Professional (64-bit) 
MonitorMonitorMonitorKeyboard
2x Dell U2410 1x Dell U2415 Insignia 46" NS-46L780A12 Logitec Wireless Illuminated Keyboard (K800) 
PowerCaseMouseMouse Pad
EVGA SuperNOVA 850 G2 Corsair Carbide Series Air 240 (White) Logitec Performance Mouse MX Vipamz Extended XXXL Gaming Mouse Pad (White) 
  hide details  
Reply
post #6 of 6
Thread Starter 
wow very helpful, crash course in php +1 to you sir
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Web Coding
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Web Coding › need Help writing html download link for media