Results 1 to 2 of 2

Thread: how do i set up a link to download a jpg file?

  1. #1
    Join Date
    May 2004
    Posts
    75

    how do i set up a link to download a jpg file?

    i have a page with some jpg thumbnails....

    i want my users to click on the file name and i want them to download the file to their pc.

    on jpeg files, if you click on the file, the file opens in the browser... i want them to get the option to download this file...

    i just want a file downloader i guess...

    i've been searching in google with little luck, because all i get is full download script softwares...

    i just need one piece of coding where i can have the files downloaded to local pcs...

    thanks

  2. #2
    Join Date
    Jan 2007
    Location
    HK
    Posts
    23
    Thinking, you should have a dynamic web technology to support it, such as PHP/JSP/ASP..

    So you can read the file stream, then output to customer side..to make it downloadble like..

    I have some Java code to make it Downloadable link.. Not sure how PHP works..wish it helps..


    response.setContentType("application/octet-stream;charset=UTF-8");
    response.setHeader("Content-disposition","attachment; filename=" + fileName);
    OutputStream os = null;
    InputStream is = null;
    try {
    os = response.getOutputStream();
    is = new FileInputStream(file);
    write(is,os);
    }
    catch (IOException e) {
    e.printStackTrace();
    }finally{
    try{
    if(os!=null){
    os.close();
    os = null;
    }
    if(is!=null){
    is.close();
    is = null;
    }
    }catch(IOException e){
    e.printStackTrace();
    }
    }

    ...........................
    ..........................
    public void write(InputStream is, OutputStream os) {
    int bytesRead = 0;
    byte[] buffer = new byte[8192];
    try {
    while ( (bytesRead = is.read(buffer, 0, 8192)) != -1) {
    os.write(buffer, 0, bytesRead);
    }
    os.flush();
    }
    catch (IOException e) {
    e.printStackTrace();
    }
    finally {
    try {
    if (os != null) {
    os.close();
    os = null;
    }
    if (is != null) {
    is.close();
    is = null;
    }
    }
    catch (IOException e) {
    e.printStackTrace();
    }

    }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •