CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Download links

Print topic Send  topic

Author Message
3140

Posts: 8
Posted: 05/29/2008, 6:06 AM

Hi folks,

Maybe I have a stupid question but anyway I need some help.

I have a grid and would like to show links like "download.php?file_id=35" instead of the real name of the file. That means I click on "download.php?file_id=35" and my browser window would open and asks for downloading the file.

How can I manage this for PHP and MySQL?

Thanks in advance,
Torsten

View profile  Send private message
wkempees


Posts: 1679
Posted: 05/29/2008, 6:17 AM

Have the grid display your ID in a label.
Next make sure you have a download.php script file in your design directory structure.
Or create a page with that name.

Next in Design Mode open the grid, select the label, right click it, change to link.
Reselect the link, edit it's properties.
Href Source press [...]
Tab general
Text to display: your choice
Static Text: press [...] and select Download.ccp
Tab Parameters
Press (+) if not displayed yet,
Parameter name, what your download expects, f.i. file_id
Source Type: Datafiled
Parameter Source: your datafield
Tab Advanced, self explanatory

All the time in the lower pane you can see the build link result.

As to the meaning of your post, you could leave the real link and change the static text only, the browser will however still display the real link (in statusbar and upon execute)

Have fun!

Walter
Source: Practice xperience and HelpFile Search topic: Link

_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)

if you liked this info PAYPAL me: http://donate.consultair.eu
View profile  Send private message
3140

Posts: 8
Posted: 05/29/2008, 6:39 AM

Quote wkempees:
As to the meaning of your post, you could leave the real link and change the static text only, the browser will however still display the real link (in statusbar and upon execute)

Thanks for your quick answer Walter! :-)
Is it possible to make the real links unvisible?

I'm working on a customer download area and real links should be unvisible for safety reasons. I cannot save the files in a blob field of my database because they're around 250MB (each file). MySQL would explode.... ;-)

Regards,
Torsten
View profile  Send private message
wkempees


Posts: 1679
Posted: 05/29/2008, 7:11 AM

Following the same concept, you could easily solve this.
Build your grid like stated earlier.
But instead of 'cloacking' the link make it real.
So follow the first part of the post and ignore
Quote :
As to the meaning of your post, you could leave the real link and change the static text only, the browser will however still display the real link (in statusbar and upon execute)

Next you would have to alter the Download.php
Feed it the file_id through the url (would rather do it different but that's up to you)
Download.php would then select the databse row containing the filename and location (as well as type), identified by the URL variable.
It could then generate the correct MIME type and offer up the file for download and/or opening.

Walter
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)

if you liked this info PAYPAL me: http://donate.consultair.eu
View profile  Send private message
3140

Posts: 8
Posted: 05/30/2008, 4:23 AM

Quote wkempees:
Next you would have to alter the Download.php
Feed it the file_id through the url (would rather do it different but that's up to you)
Download.php would then select the databse row containing the filename and location (as well as type), identified by the URL variable.
It could then generate the correct MIME type and offer up the file for download and/or opening.

Walter,
That is not clear for me. I've managed the grid so far and download works but the link is visible. What I'm doing wrong?

Torsten
View profile  Send private message
3140

Posts: 8
Posted: 05/30/2008, 5:17 AM

Quote 3140:
Walter,
That is not clear for me. I've managed the grid so far and download works but the link is visible. What I'm doing wrong?

Torsten

I've forgot to mention that the links in my grid are showing this url:
http://localhost/customer/download.php?file_id=35&location=test123.zip
But when I click on it, nothing happens.... :-(

Torsten
View profile  Send private message
wkempees


Posts: 1679
Posted: 05/30/2008, 11:25 AM

Is your file test123.zip in database row with ID=35?

If so, you need to take a look at your links parameters........
the parameter should be
file_id type datafield ID ( or id or whatever identifies the row.
I think you still have your original link parameter ther too, delet that.

Walter
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)

if you liked this info PAYPAL me: http://donate.consultair.eu
View profile  Send private message
mentecky

Posts: 321
Posted: 05/30/2008, 2:34 PM

3140,

Here's how I make files downloadable:

First get your uploads working... there are plenty of tips here for that feature.

Create a blank page, in this example "download". Click the blank page and in Properties/Events select On Before Show and "Add Code...".

Put the following in the event handler:
   // Edit this to point at your document/image path    
   $path = dirname(__FILE__)."/documents/";    
     
   // Change this to your DB class     
   $db = new clsDBmentecky();  
  
   // Change this to matck your table definition	    
   $file_name = CCDLookup("file_name", "files", "file_id=".$db->ToSQL(CCGetParam("file_id", "-1"), ccsInteger), $db);    
          
   $file_parts = explode(".", $file_name);    
   $ext = strtoupper($file_parts[count($file_parts) - 1]);    
    
   // Set header information    
   header('pragma: no-cache');    
   header('expires: 0');    
   header('Cache-Control: no-cache');    
   header('Content-Length: '.filesize($path.$file_name));    
   header('Content-Disposition: attachment; filename="'.CCGetOriginalFileName($file_name).'"');    
    
   // do some MIME stuff    
   if ($ext == "DOC")    
   {    
      $content_type = "application/msword";    
   }    
   else if ($ext == "PDF")    
   {    
      $content_type = "application/pdf";	      
   }    
   else if ($ext == "RTF")    
   {    
      $content_type = "application/rtf";	      
   }    
   else if (($ext == "MPG2") || ($ext == "MP3") || ($ext == "MP2"))    
   {    
      $content_type = "audio/mpeg";	      
   }    
   else if ($ext == "WAV")    
   {    
      $content_type = "audio/x-wav";	      
   }    
   else if ($ext == "GIF")    
   {    
      $content_type = "image/gif";	      
   }    
   else if ($ext == "JPG")    
   {    
      $content_type = "image/jpeg";	      
   }    
   else if ($ext == "PNG")    
   {    
      $content_type = "image/png";	      
   }    
   else if (($ext == "TIF") || ($ext == "TIFF"))    
   {    
      $content_type = "image/tiff";	      
   }    
   else    
   {    
      $content_type = "text/plain";	      
   }    
    
   header('Content-type: '.$content_type);    
    
   // output the file    
   readfile($path.$file_name);    
    
   exit;  

The above assumes a table called "files" with file_id, file_desc and file_name as it's columns.

On your download page, set the link to "download.ccp" with a parameter of "link_id".

You can see it work on a demo page at: http://www.mentecky.com/demo/files_list.php

Currently you can upload JPG, GIF and TXT files, up to 20K. I will be disabling UPLOAD there once this problem is resolved though.

Hope that works for you.

Rick

_________________
http://www.ccselite.com
View profile  Send private message
jjrjr1


Posts: 942
Posted: 05/31/2008, 1:34 PM

Hi

This is great help. I do have one question for you guys.

If you wanted to link to the download file this way but want the file to automatically open in the application instead of the open save cancel dialoge box, what would you do?

Is there a way to bypass the dialoge box?

Thanks

_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com
View profile  Send private message
mentecky

Posts: 321
Posted: 05/31/2008, 5:09 PM

Quote jjrjr1:
Hi

This is great help. I do have one question for you guys.

If you wanted to link to the download file this way but want the file to automatically open in the application instead of the open save cancel dialoge box, what would you do?

Is there a way to bypass the dialoge box?

Thanks


John,

Commenting out the following line will make it an "inline" download and should load in the browser window.

header('Content-Disposition: attachment; filename="'.CCGetOriginalFileName($file_name).'"'); 

Rick
_________________
http://www.ccselite.com
View profile  Send private message
mentecky

Posts: 321
Posted: 05/31/2008, 6:11 PM

John,

I replaced the following in my "download.php" code:
header('Content-Disposition: attachment; filename="'.CCGetOriginalFileName($file_name).'"'); 

With:
   if (CCGetParam("inline", "0") == "0")  
   {    
      header('Content-Disposition: attachment; filename="'.CCGetOriginalFileName($file_name).'"');    
   }  

Then I added an additional parameter "inline=1" to a "View" link. See if that's what you are looking for at http://www.mentecky.com/demo/files_list.php

Rick



_________________
http://www.ccselite.com
View profile  Send private message
jjrjr1


Posts: 942
Posted: 06/01/2008, 9:42 AM

Hey Rick

That works great. Question is, will this only display if there is a plugin for the browser or will the associated application load?

For example, video files, excel spread sheets etc

Thanks very much


_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com
View profile  Send private message
mentecky

Posts: 321
Posted: 06/01/2008, 6:11 PM

Quote jjrjr1:
Hey Rick

That works great. Question is, will this only display if there is a plug-in for the browser or will the associated application load?

For example, video files, excel spread sheets etc

Thanks very much


Yes, if Content-Disposition is not specified, your browser decides how to display it. In most cases that will be within the browser as long as it knows how to handle the MIME type.

I have noticed that by changing my above "if" statement to:
   if (CCGetParam("inline", "0") == "0")  
   {    
      header('Content-Disposition: attachment; filename="'.CCGetOriginalFileName($file_name).'"');    
   }  
   else  
   {    
      header('Content-Disposition: inline; filename="'.CCGetOriginalFileName($file_name).'"');    
   }  

has the same functionality, but if the browser chooses to use the download window it will have the original filename.

Rick
_________________
http://www.ccselite.com
View profile  Send private message
3140

Posts: 8
Posted: 06/02/2008, 1:05 AM

Quote mentecky:
3140,

Here's how I make files downloadable:

First get your uploads working... there are plenty of tips here for that feature.

Create a blank page, in this example "download". Click the blank page and in Properties/Events select On Before Show and "Add Code...".

Put the following in the event handler:
   // Edit this to point at your document/image path    
   $path = dirname(__FILE__)."/documents/";    
     
   // Change this to your DB class     
   $db = new clsDBmentecky();  
  
   // Change this to matck your table definition	    
   $file_name = CCDLookup("file_name", "files", "file_id=".$db->ToSQL(CCGetParam("file_id", "-1"), ccsInteger), $db);    
          
   $file_parts = explode(".", $file_name);    
   $ext = strtoupper($file_parts[count($file_parts) - 1]);    
    
   // Set header information    
   header('pragma: no-cache');    
   header('expires: 0');    
   header('Cache-Control: no-cache');    
   header('Content-Length: '.filesize($path.$file_name));    
   header('Content-Disposition: attachment; filename="'.CCGetOriginalFileName($file_name).'"');    
    
   // do some MIME stuff    
   if ($ext == "DOC")    
   {    
      $content_type = "application/msword";    
   }    
   else if ($ext == "PDF")    
   {    
      $content_type = "application/pdf";	      
   }    
   else if ($ext == "RTF")    
   {    
      $content_type = "application/rtf";	      
   }    
   else if (($ext == "MPG2") || ($ext == "MP3") || ($ext == "MP2"))    
   {    
      $content_type = "audio/mpeg";	      
   }    
   else if ($ext == "WAV")    
   {    
      $content_type = "audio/x-wav";	      
   }    
   else if ($ext == "GIF")    
   {    
      $content_type = "image/gif";	      
   }    
   else if ($ext == "JPG")    
   {    
      $content_type = "image/jpeg";	      
   }    
   else if ($ext == "PNG")    
   {    
      $content_type = "image/png";	      
   }    
   else if (($ext == "TIF") || ($ext == "TIFF"))    
   {    
      $content_type = "image/tiff";	      
   }    
   else    
   {    
      $content_type = "text/plain";	      
   }    
    
   header('Content-type: '.$content_type);    
    
   // output the file    
   readfile($path.$file_name);    
    
   exit;  

The above assumes a table called "files" with file_id, file_desc and file_name as it's columns.

On your download page, set the link to "download.ccp" with a parameter of "link_id".

You can see it work on a demo page at: http://www.mentecky.com/demo/files_list.php

Currently you can upload JPG, GIF and TXT files, up to 20K. I will be disabling UPLOAD there once this problem is resolved though.

Hope that works for you.

Rick



Rick,
That works fine. :-)
Thank you so much!

Have a nice week,
Torsten
View profile  Send private message
mentecky

Posts: 321
Posted: 06/02/2008, 1:41 AM

Torsten,

Glad we could help!

You have a good week also.

Rick
_________________
http://www.ccselite.com
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.