This topic is locked
[SOLVED]

 event on click

12/1/2009 8:42:41 AM
PHPRunner General questions
T
tkjerulf author

Hi, could someone point me in the right direction,I have within a table, a field containing downloadable information within a zip file.
when a user clicks the link for the file, I like to store the count to my database, how would i best achive this?
cheers

T

J
Jane 12/1/2009

Hi,
edit generated ..._download.php file for this purpose.

T
tkjerulf author 12/2/2009



Hi,
edit generated ..._download.php file for this purpose.


Hi, well i don't see any xxxx_download.php file.
Im using type file for the database field which is a BLOB field containing a zip file..

did i do anything wrong since i dont see the generated file.

cheers

T

J
Jane 12/3/2009

Hi,
if you save files in the database directly check ..._getfile.php file.

T
tkjerulf author 12/3/2009

Thanks, well Im checking the xxx_getfile.php file, I pasted some popup and echo lines into it, to see when it was called,

as it seems, phprunner never enters the "getfile" code... or im really missing something here

please see code from getfile below, if someone could help it would be great!
cheers

T



Hi,
if you save files in the database directly check ..._getfile.php file.


<?php

ini_set("display_errors","1");

ini_set("display_startup_errors","1");

session_cache_limiter("none");

set_magic_quotes_runtime(0);
include("include/dbcommon.php");

include("include/memberdl_purschases_variables.php");

if(!@$_SESSION["UserID"] || !CheckSecurity(@$SESSION["".$strTableName."_OwnerID"],"Search"))

{

header("Location: login.php");

return;

}

$msg="HELLO WORLD!";

echo "<script langauge=\"javascript\">alert(\"".$msg."\");</script>";


$strFilename=$_GET["filename"];

$ext=substr($strFilename,strlen($strFilename)-4);
switch($ext)

{

case ".asf":

$ctype = "video/x-ms-asf";

case ".avi":

$ctype = "video/avi";

case ".doc":

$ctype = "application/msword";

case ".zip":

$ctype = "application/zip";

case ".xls":

$ctype = "application/vnd.ms-excel";

case ".gif":

$ctype = "image/gif";

case ".jpg":

case "jpeg":

$ctype = "image/jpeg";

case ".wav":

$ctype = "audio/wav";

case ".mp3":

$ctype = "audio/mpeg3";

case ".mpg":

case "mpeg":

$ctype = "video/mpeg";

case ".rtf":

$ctype = "application/rtf";

case ".htm":

case "html":

$ctype = "text/html";

case ".asp":

$ctype = "text/asp";

default:

$ctype = "application/octet-stream";

}
$field = @$_GET["field"];

if(!CheckFieldPermissions($field))

return "";
// construct sql
$keys=array();

$keys["ID"]=postvalue("key1");

$where=KeyWhere($keys);
//$sql=$gstrSQL;

//$sql = AddWhere($sql,$where);
$sql = gSQLWhere($where);
$rs = db_query($sql,$conn);

if(!$rs || !($data=db_fetch_array($rs)))

{

header("Location: login.php");

return;

}

header("Content-Type: ".$ctype);

header("Content-Disposition: attachment;Filename=\"".$strFilename."\"");

header("Cache-Control: private");

$value=db_stripslashesbinary($data[$field]);

header("Content-Length: ".strlen($value));

echo "HI THERE!";



echobig($value);

return;
?>

T
tkjerulf author 12/3/2009

ok, to anyone else who needs smiliar functions - this works fine.
at xxx_getfile.php i can simply call a function that saves some information to my database when the url are clicked.

just fine - thanks for the help.



Thanks, well Im checking the xxx_getfile.php file, I pasted some popup and echo lines into it, to see when it was called,

as it seems, phprunner never enters the "getfile" code... or im really missing something here

please see code from getfile below, if someone could help it would be great!
cheers

T
<?php

ini_set("display_errors","1");

ini_set("display_startup_errors","1");

session_cache_limiter("none");

set_magic_quotes_runtime(0);
include("include/dbcommon.php");

include("include/memberdl_purschases_variables.php");

if(!@$_SESSION["UserID"] || !CheckSecurity(@$SESSION["".$strTableName."_OwnerID"],"Search"))

{

header("Location: login.php");

return;

}
$strFilename=$_GET["filename"];

$ext=substr($strFilename,strlen($strFilename)-4);
switch($ext)

{

case ".asf":

$ctype = "video/x-ms-asf";

case ".avi":

$ctype = "video/avi";

case ".doc":

$ctype = "application/msword";

case ".zip":

$ctype = "application/zip";

case ".xls":

$ctype = "application/vnd.ms-excel";

case ".gif":

$ctype = "image/gif";

case ".jpg":

case "jpeg":

$ctype = "image/jpeg";

case ".wav":

$ctype = "audio/wav";

case ".mp3":

$ctype = "audio/mpeg3";

case ".mpg":

case "mpeg":

$ctype = "video/mpeg";

case ".rtf":

$ctype = "application/rtf";

case ".htm":

case "html":

$ctype = "text/html";

case ".asp":

$ctype = "text/asp";

default:

$ctype = "application/octet-stream";

}
$field = @$_GET["field"];

if(!CheckFieldPermissions($field))

return "";
// construct sql
$keys=array();

$keys["ID"]=postvalue("key1");

$where=KeyWhere($keys);
//$sql=$gstrSQL;

//$sql = AddWhere($sql,$where);
$sql = gSQLWhere($where);
$rs = db_query($sql,$conn);

if(!$rs || !($data=db_fetch_array($rs)))

{

header("Location: login.php");

return;

}

header("Content-Type: ".$ctype);

header("Content-Disposition: attachment;Filename=\"".$strFilename."\"");

header("Cache-Control: private");

$value=db_stripslashesbinary($data[$field]);

header("Content-Length: ".strlen($value));
echobig($value);

return;
?>