473,772 Members | 3,712 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dowload script

9 New Member
Dear Sir,

Hello ! I want to write a script to allow downloading a file from server, which first asks for the path to store the file and then downloads to user's local machine.

Please guide me.

Thanks & Regards,

Naimesh Trivedi
[Email-Removed-Moderator]
Sep 19 '07 #1
2 1763
ak1dnar
1,584 Recognized Expert Top Contributor
You can use this sample script for download files from server.(didn't test)
Then the default download manger for the browser will do the needful for you. Here you will get the save as dialog box. Its completely happening on the browser level. not because of the script, but with the support of headers you are calling to the download manager.
Thanks and good luck.
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. $file = 'some_file_name_here.pdf';
  3. if($file)
  4. {
  5. header("Content-Type: application/octet-stream");
  6. header("Content-Length: " . filesize($file));
  7. header('Content-Disposition: attachment; filename="'.$file.'"');
  8. readfile($file);
  9. exit();
  10. }
  11. ?>

Welcome to The Scripts !
Sep 19 '07 #2
nbt725
9 New Member
You can use this sample script for download files from server.(didn't test)
Then the default download manger for the browser will do the needful for you. Here you will get the save as dialog box. Its completely happening on the browser level. not because of the script, but with the support of headers you are calling to the download manager.
Thanks and good luck.
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. $file = 'some_file_name_here.pdf';
  3. if($file)
  4. {
  5. header("Content-Type: application/octet-stream");
  6. header("Content-Length: " . filesize($file));
  7. header('Content-Disposition: attachment; filename="'.$file.'"');
  8. readfile($file);
  9. exit();
  10. }
  11. ?>

Welcome to The Scripts !
Thanks it worked. Thanks for the help.

Naimesh Trivedi
Sep 20 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
12987
by: Mike Daniel | last post by:
I am attempting to use document.write(pageVar) that displays a new html page within a pop-up window and the popup is failing. Also note that pageVar is a complete HTML page containing other java scripts. Being a javascript newbie and after significant testing, I suspect that the document.write fails after finding a </script> within pageVar. Does a trick exist that enables one to slightly alter pageVar whereby enabling...
13
1915
by: dvsbis | last post by:
does anybody have example of file download using java script thanks dave dvs_bis@sbcglobal.net
2
2516
by: marcos | last post by:
sorry, but my english are very bad... how lto dowload visual basic 6.0 from internet?
3
2959
by: Water Cooler v2 | last post by:
Questions: 1. Can there be more than a single script block in a given HEAD tag? 2. Can there be more than a single script block in a given BODY tag? To test, I tried the following code. None of the script gets executed. Can someone please give me a direction as to what I may be missing? Thanks.
2
2972
by: bilaribilari | last post by:
Hi all, I am using Tidy (C) for parsing html pages. I encountered a page that has some script as follows: <script> .... var abc = "<script>some stuff here</" + "script>"; .... </script>
2
1499
by: comick | last post by:
Hello all, i have a asp.net c# web app 2.0 I have a pdf generation with a third part sw, but i cant download pdf in a new window, from a folder inside my web site. The code i try to use is this: ...pdf Generation.. Response.Clear(); Response.ContentType = "application/pdf";
19
3827
by: thisis | last post by:
Hi All, i have this.asp page: <script type="text/vbscript"> Function myFunc(val1ok, val2ok) ' do something ok myFunc = " return something ok" End Function </script>
1
1790
by: nkamalnath | last post by:
hi, How to dowload a file using javascript.
1
47485
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or “save“. I’m going to show you how to do that using a perl script. What You Need Any recent...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10261
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10104
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9912
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8934
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6715
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.