Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Dowload blobs from Database

Explorer ,
Jun 04, 2009 Jun 04, 2009

I know this is not the best way to store files but I have inherited an old php script which I am converting to CF because php is useless.

Now i have a script to do this in php but can this be achived with CF? It is just a quick fix until I have time to rework the CMS

<?php
if(isset($_GET['id']))
{
// if id is set then get the file with the id from database


$id    = $_GET['id'];
$query = "SELECT name, type, size, content " .
         "FROM upload WHERE id = '$id'";

$result = mysql_query($query) or die('Error, query failed');
list($name, $type, $size, $content) =                                  mysql_fetch_array($result);

header("Content-length: $size");
header("Content-type: $type");
header("Content-Disposition: attachment; filename=$name");
echo $content;

i
exit;
}

?>

437
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , Jun 04, 2009 Jun 04, 2009

My php experience is NILL, but applying basic coding experience I believe your CFML will be close to this.

<cfif structKeyExists(url,"id")>

  <cfquery datasource="..." name="result">

    SELECT name,type,size,content

    FROM upload

    WHERE id = <cfqueryparam value="#url.id#" cfsqltype="cf_sql_integer">

  </cfquery>

  <cfheader name="Content-Disposition: atachment; filename=#result.name#">

  <cfcontent type="#result.type#" reset="yes">

  #result.content#

</cfif>

If any of this content can be binary, then

...
Translate
Valorous Hero ,
Jun 04, 2009 Jun 04, 2009

My php experience is NILL, but applying basic coding experience I believe your CFML will be close to this.

<cfif structKeyExists(url,"id")>

  <cfquery datasource="..." name="result">

    SELECT name,type,size,content

    FROM upload

    WHERE id = <cfqueryparam value="#url.id#" cfsqltype="cf_sql_integer">

  </cfquery>

  <cfheader name="Content-Disposition: atachment; filename=#result.name#">

  <cfcontent type="#result.type#" reset="yes">

  #result.content#

</cfif>

If any of this content can be binary, then you may also need to use one or more of the toBinary() toBase64(), isBinary(), binaryDecode() or other relevant functions.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 05, 2009 Jun 05, 2009
LATEST

Thanks Ian that kind of works (in Firefox anyway).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources