Web Design Forums

PHP

Have questions about PHP? Ask them here and our experts will assist you before you know it! You can also find help in the documentation at PHP.net.

need code if this is possible



Site of the Month Nominations
ENTER YOUR SITE NOW!

Reply
 
LinkBack Thread Tools
Old May 30 '09, 02:40 AM (#1)
chikulanikader is offline
New Member!
 
chikulanikader's Avatar
 
Join Date: May 2009
Posts: 2
chikulanikader is an unknown quantity at this point
need code if this is possible

What I want to do is add a code that makes a picture downloadable. (hope that makes sense)

I don't want the picture to appear like what happens when you click on a thumbnail and a larger picture appears. The one I have is 3 mgs in size and is for club members who want it for printing purposes.

Is there some kind of code where if I click on the words "corvette sunset" a dialog box appears and asks if you want to download the file.

Hope I explained this well enough

Thanks for any help
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old May 30 '09, 11:49 AM (#2)
mlseim is offline
WDF Staff
 
mlseim's Avatar
 
Join Date: April 2004
Location: Cottage Grove, Minnesota
Posts: 3,401
mlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud of
This has a couple of parts to it.

1) You mention "club members".
Does that mean they have logged into your website?
I ask this because you may have something that will check to
see if the site visitor is logged in ... other visitors can't download the image.

2) The image could be stored in a secret directory, and you
serve the image (or photo) using PHP. The site user would be
able to see the photo on their browser (and copy it), but they
won't see where the photo originated from.

This is a simple example (I found this on the internet).
It does open a dialog box (open or save?), but the user
does not know where the image came from.
PHP Code:
<?php    
if($_GET){
    if(
$_GET['file']) {
        
$filename $_GET['file'];
        
$download_path "files/";
    }

    if(
eregi("\.\."$filename)) die("I'm sorry, you may not download that file.");
    
$file str_replace(".."""$filename);
    if(
eregi("\.ht.+"$filename)) die("I'm sorry, you may not download that file.");
    
$file "$download_path$file";
    if(!
file_exists($file)) die("I'm sorry, the file doesn't seem to exist.");
    
$type filetype($file);
    
$today date("F j, Y, g:i a");
    
$time time();

    
header("Content-type: $type");
    
header("Content-Disposition: attachment;filename=$filename");
    
header("Content-Transfer-Encoding: binary");
    
header("Cache-Control: ");
    
header("Pragma: ");
    
set_time_limit(0);
    
readfile($file);
}
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 10 '09, 04:05 AM (#3)
Danny[MLWA] is offline
WDF Regular
 
Danny[MLWA]'s Avatar
 
Join Date: June 2009
Location: Goldsboro, North Carolina, USA
Posts: 109
Danny[MLWA] is on a distinguished road
The best way to do it:

Code:
define('FILE_PATH', '/path/to/your/file/');
define('FILE_NAME', 'some_image.jpg');
header('Content-type: application/file');
header('Content-disposition: attachment; filename="'. FILE_NAME .'"');
readfile(FILE_PATH . FILE_NAME);
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 10 '09, 12:38 PM (#4)
Dorky is offline
Freelance
 
Dorky's Avatar
 
Join Date: June 2009
Location: Destin Florida
Posts: 905
Dorky will become famous soon enough
how would you implement that without getting a header already sent error? is this to be the start of a new .php or on the same page.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 10 '09, 01:36 PM (#5)
Danny[MLWA] is offline
WDF Regular
 
Danny[MLWA]'s Avatar
 
Join Date: June 2009
Location: Goldsboro, North Carolina, USA
Posts: 109
Danny[MLWA] is on a distinguished road
Quote:
Originally Posted by Dorky
how would you implement that without getting a header already sent error? is this to be the start of a new .php or on the same page.
Yes, quite frankly that has to be the first and only thing in the document...

If you want to make the file more universal... Say if you have just document.php to display some content, but display something else by appending ?file=filename to document.php without creating a new php file you would do something like this:
Code:
<?php
if(isset($_REQUEST['file']))
{
define('FILE_PATH', '/path/to/your/file/');
define('FILE_NAME', 'some_image.jpg');
header('Content-type: application/file');
header('Content-disposition: attachment; filename="'. $_REQUEST['file'] .'"');
readfile(FILE_PATH . $_REQUEST['file']);
} else {

?>
<html>
<head>
<title>Somepage</title>
</head>
<body>
Some body stuff here.
</body>
</html>
<?php
}
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 10 '09, 03:11 PM (#6)
Dorky is offline
Freelance
 
Dorky's Avatar
 
Join Date: June 2009
Location: Destin Florida
Posts: 905
Dorky will become famous soon enough
very cool
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old July 3 '09, 02:14 AM (#7)
nitin is offline
New Member!
 
nitin's Avatar
 
Join Date: July 2009
Posts: 14
nitin is an unknown quantity at this point
for this you can use code behind.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

  Web Design Forums » Programming Help » PHP

Bookmarks


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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Top 21 PHP Programming mistakes thexchord PHP 19 June 18 '10 02:20 PM
Modifying code to make file upload optional ravensjeff PHP 3 March 12 '09 09:23 AM
Code tags reminder filburt1 Announcements 4 November 3 '05 06:29 PM
JavaScript Dropdown Menu Tutorial [Li] Brad Coding Articles & Tutorials 12 August 17 '04 03:16 PM
Stop direct linking with this code illu HTML and CSS Help 0 February 19 '04 11:40 AM

 
User Infomation
Your Avatar

Site Of The Month

Ticket Cake
Ticket Cake

Ticket Cake is a drupal based event ticketing platform. It features that ability to browse events and share them.

Nominate Your Site Now!

Advertisement
WolfCMS.org

Latest Articles
- by RickM
- by bfsog

Advertisement

Partner Links



All times are GMT -4. The time now is 02:38 AM.


WebDesignForums.net is Copyright © 2010 RikeMedia.

SEO by vBSEO

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163