Re: stream wrappers

From: Date: Wed, 01 Sep 2004 20:40:22 +0000
Subject: Re: stream wrappers
References: 1 2 3 4 5  Groups: php.general 
Request: Send a blank email to php-general+get-195464@lists.php.net to get a copy of this message
From: "jarell" <jcdouville@sbcglobal.net>
Here's my db_update function then your code with some mods: <?php function update_db($location) { require_once('/usr/home/doc/mysqlconnect.php'); $query = "SELECT dl_count FROM downloads WHERE filelocation = '$location'"; $result = mysql_query($query); $dl_count = mysql_result($result, 0, "dl_count"); $dl_count++; $update = "UPDATE downloads SET dl_count = '$dl_count' WHERE filelocation = '$location'"; $result = mysql_query($update); if(!$result) { mysql_close(); die(); } mysql_close(); } class onetime { var $fp = FALSE; function stream_open($path, $mode, $options, $opened_path) { [snip]
stream_wrapper_register("one","onetime") or die(); readfile("one://$filelocation");
I don't really understand why you're using a custom stream here or what you're hoping to accomplish. you're incrementing the download count, but not really checking it for any limit. It wouldn't really make sense to put the checks in the stream. Check them outside of it and either show an error message in HTML or send the file headers and the data with readfile() and the normal file:// stream. ---John Holmes...

« previous php.general (#195464) next »