Web Design Forum: Save a file ? - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Save a file ? A basic web page that allows the user to download a file?

#1 User is offline   ltns1 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 13-January 12
  • Reputation: 0

Posted 14 January 2012 - 12:06 AM

Hi,

Im rather new to web dev, or returning...

How do I make a HTML web page that lists files that a user can click on and download?

Is it really that complex? ASP.. jsp.. etc etc... NO! its cant be that complex... I just want to list files and give the option to save them back to the local machine...

But its like I have just discovered that 20ys of HTML has evolved to not allowing this ???

Can anyone give some practical strategy?
0

#2 User is online   zed 

  • Web Guru
  • Group: Moderators
  • Posts: 4,941
  • Joined: 25-May 10
  • Reputation: 703
  • Gender:Male
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 14 January 2012 - 08:27 AM

just give them a folder on your server that they can view? No HTML required.
0

#3 User is online   roothost 

  • Currently accepting new clients
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,463
  • Joined: 06-February 11
  • Reputation: 73
  • Gender:Male
  • Location:Lewes, East Sussex
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 14 January 2012 - 09:23 AM

save the file in a .zip and upload the zip? same as it always has been?
0

#4 User is offline   Samus 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 367
  • Joined: 05-August 11
  • Reputation: 27
  • Gender:Male
  • Location:Hackney, London, UK
  • Experience:Intermediate
  • Area of Expertise:Web Developer

Posted 14 January 2012 - 12:24 PM

Generally you would just have to link the file to someone and it will be downloaded automatically. But some browsers act differently with some file extensions.

For example take Google Chrome. If I clicked a link with a .mp3 extension, chrome will play it straight through the browser rather than downloading it. In situations like this, you can choose to just switch to a different browser that doesn't have the inbuilt player. Or you could use php to force a download with a little bit of server headers.

Something like this:
<?php
header('Content-type: audio/mpeg');
header('Content-disposition: attachment; filename=samus.mp3');
header("Content-Transfer-Encoding: binary");
header('Expires: 0');
header('Pragma: no-cache');
?>


The latter would be my personal option.
0

#5 User is offline   ltns1 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 13-January 12
  • Reputation: 0

Posted 14 January 2012 - 10:44 PM

View PostSamus, on 14 January 2012 - 12:24 PM, said:

Generally you would just have to link the file to someone and it will be downloaded automatically. But some browsers act differently with some file extensions.

For example take Google Chrome. If I clicked a link with a .mp3 extension, chrome will play it straight through the browser rather than downloading it. In situations like this, you can choose to just switch to a different browser that doesn't have the inbuilt player. Or you could use php to force a download with a little bit of server headers.

Something like this:
<?php
header('Content-type: audio/mpeg');
header('Content-disposition: attachment; filename=samus.mp3');
header("Content-Transfer-Encoding: binary");
header('Expires: 0');
header('Pragma: no-cache');
?>


The latter would be my personal option.



Thanks for the suggestions... Samus esp. I will have to 'try' the above php solution.

Just to be clear... And maybe get a bit more advice...

Its a piece of a web page/application I just want to make my life easier...

I want the user to click a button( i can do that) be shown a fresh list of the files there.. and choose one to 'save as'
The files are just txt. the save as diag comes up and I same my file to my laptop.

I think I can just about handle php and HTML, xml, but the rest sadly is beyond my radar. i.e if you find yourself looking up ASP on wikipedia... its maybe not a good idea to start trying to implement something with it.. hehe.

Even outside of the box ideas are welcome... Am I over complicating this?
0

#6 User is offline   Samus 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 367
  • Joined: 05-August 11
  • Reputation: 27
  • Gender:Male
  • Location:Hackney, London, UK
  • Experience:Intermediate
  • Area of Expertise:Web Developer

Posted 14 January 2012 - 11:43 PM

If you already have PHP experience, i'd suggest you jump straight into a framework, specifically codeigniter. There are several libraries and functions that make tasks like this easier, especially when developing an app.

For example, the download helper

Only pass 2 arguements to the function, the name you want the downloaded files to be called and the file's location. And all the appropriate headers are created for that download.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users