There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Web Design & Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
Force file download


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
dannyn's Avatar
Senior Member with 944 posts.
 
Join Date: Nov 2007
Experience: Intermediate
25-May-2008, 11:35 PM #1
Force file download
I need help with force file download for asp.
Thanks.
TheRobatron's Avatar
Computer Specs
Senior Member with 417 posts.
 
Join Date: Oct 2007
Location: England
Experience: Intermediate
30-May-2008, 04:58 AM #2
Try looking here.
dannyn's Avatar
Senior Member with 944 posts.
 
Join Date: Nov 2007
Experience: Intermediate
31-May-2008, 07:02 PM #3
so should i use the first or second example?
I really need help with this, and I am only 15 years old, and this is the first time i have worked with asp.
Thanks alot!
TheRobatron's Avatar
Computer Specs
Senior Member with 417 posts.
 
Join Date: Oct 2007
Location: England
Experience: Intermediate
08-Jun-2008, 10:10 AM #4
I'm not very familiar with ASP, so I don't know which example you should use, but try both and see which works best.
dannyn's Avatar
Senior Member with 944 posts.
 
Join Date: Nov 2007
Experience: Intermediate
08-Jun-2008, 02:30 PM #5
neither, thats my problem.
http://senior.bpsepforums.org/ thats where it is.
thanks!
TheRobatron's Avatar
Computer Specs
Senior Member with 417 posts.
 
Join Date: Oct 2007
Location: England
Experience: Intermediate
08-Jun-2008, 05:06 PM #6
Have you considered using PHP? It seems simpler and I understand the code:
PHP Code:
<?
function force_download($file)
{
    
$dir      "../log/exports/";
    if ((isset(
$file))&&(file_exists($dir.$file))) {
       
header("Content-type: application/force-download");
       
header('Content-Disposition: inline; filename="' $dir.$file '"');
       
header("Content-Transfer-Encoding: Binary");
       
header("Content-length: ".filesize($dir.$file));
       
header('Content-Type: application/octet-stream');
       
header('Content-Disposition: attachment; filename="' $file '"');
       
readfile("$dir$file");
    } else {
       echo 
"No file selected";
    } 
//end if

}//end function
?>
TheRobatron's Avatar
Computer Specs
Senior Member with 417 posts.
 
Join Date: Oct 2007
Location: England
Experience: Intermediate
08-Jun-2008, 05:07 PM #7
Have you considered using PHP? It seems simpler and I understand the code:
PHP Code:
<?
function force_download($file)
{
    
$dir      "../log/exports/";
    if ((isset(
$file))&&(file_exists($dir.$file))) {
       
header("Content-type: application/force-download");
       
header('Content-Disposition: inline; filename="' $dir.$file '"');
       
header("Content-Transfer-Encoding: Binary");
       
header("Content-length: ".filesize($dir.$file));
       
header('Content-Type: application/octet-stream');
       
header('Content-Disposition: attachment; filename="' $file '"');
       
readfile("$dir$file");
    } else {
       echo 
"No file selected";
    } 
//end if

}//end function
?>
dannyn's Avatar
Senior Member with 944 posts.
 
Join Date: Nov 2007
Experience: Intermediate
08-Jun-2008, 05:45 PM #8
I have asp servers...
It is a possibility though.
I will need help on where to put the file path and such.

Last edited by dannyn : 08-Jun-2008 06:28 PM.
Eriksrocks's Avatar
Computer Specs
Senior Member with 1,859 posts.
 
Join Date: Aug 2005
Location: Minnesota
Experience: Advanced
08-Jun-2008, 10:21 PM #9
The general concept to this is to force the MIME type of application/force-download or application/octet-stream through the headers of the page. The example TheRobatron posted is how to do it in PHP, you'll need to accomplish the same thing in ASP. As I'm not familiar with ASP, I wouldn't know the exact code to write, but you're going for the same concept.
dannyn's Avatar
Senior Member with 944 posts.
 
Join Date: Nov 2007
Experience: Intermediate
08-Jun-2008, 10:44 PM #10
Yea, I understand what I am trying to do.
I just needed someone to write the code for asp, i really need this so i am thinking of switching one of my servers over to Linux so i can run the code.
Thanks for the responses.
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,208 posts.
 
Join Date: Oct 2006
09-Jun-2008, 08:24 AM #11
dannyn's Avatar
Senior Member with 944 posts.
 
Join Date: Nov 2007
Experience: Intermediate
13-Jun-2008, 02:01 AM #12
The robatron what variables do i have to replace?
I am using php 4
TheRobatron's Avatar
Computer Specs
Senior Member with 417 posts.
 
Join Date: Oct 2007
Location: England
Experience: Intermediate
13-Jun-2008, 03:13 PM #13
All you would have to change is the $dir variable to the folder you want to download to, relative to the page. Note: you can just leave it blank and give the full file path when you call the function.
PHP Code:
   <?
function force_download($file)
{
    
$dir      "../log/exports/";
    if ((isset(
$file))&&(file_exists($dir.$file))) {
       
header("Content-type: application/force-download");
       
header('Content-Disposition: inline; filename="' $dir.$file '"');
       
header("Content-Transfer-Encoding: Binary");
       
header("Content-length: ".filesize($dir.$file));
       
header('Content-Type: application/octet-stream');
       
header('Content-Disposition: attachment; filename="' $file '"');
       
readfile("$dir$file");
    } else {
       echo 
"No file selected";
    } 
//end if

}//end function
?>
And when you call the function you specify the file:
PHP Code:
<?php
force_download
("file.jpg");
?>
__________________
There's no place like 127.0.0.1

dannyn's Avatar
Senior Member with 944 posts.
 
Join Date: Nov 2007
Experience: Intermediate
13-Jun-2008, 08:08 PM #14
<?
$filename = "http://bpsepforums.org/Storage/Final.mov";
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: $ctype");
header('Content-Disposition: attachment; filename="Final.mov";');
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename));
readfile($filename);
exit();
?>

thats what i have, now what do i do with it.
I dont understand this to much.
How will filename work if it is on a differnt computer

Last edited by dannyn : 13-Jun-2008 08:17 PM.
Eriksrocks's Avatar
Computer Specs
Senior Member with 1,859 posts.
 
Join Date: Aug 2005
Location: Minnesota
Experience: Advanced
13-Jun-2008, 09:33 PM #15
You put it in a PHP script and run it or link to it on your website.
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 01:23 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.