Re: [PHP] File Downloads
At 4:41 PM -0500 5/28/10, Karl DeSaulniers wrote: On May 28, 2010, at 4:25 PM, tedd wrote: At 3:39 PM -0500 5/28/10, Karl DeSaulniers wrote: Hello, How can I go about restricting the number of downloads of a file on my server? For Eg: if I want a music track to only be able to be downloaded by 150 people and thats it.. ever, how can I go about doing this? Karl: Just have the download pass through a script that counts, such as found here: http://sperling.com/freeware.php When someone click the link, it activates a script that provides the download and saves a count. It would be trivial to stop the download at a specific number. Cheers, tedd Hey thanks Tedd. Quick question. Were you referring me to this link to download one of their demos or just to show that they count their downloads? EG: Binary-Tree v1.1 Downloads: 2806 Karl: What I was showing you was a working example of what you want. The link simply calls a script that: 1) provides the download for the user; 2) writes a count to a file. You also said: The users will have gone through a registration and login to get to the downloads. The files will be served from MySQL and output to HTML of Flash. This is for a small project of limited edition audio or pictures or scripts, etc. Hens, "I'd like" to limit each user in the allotted 150 to be able to download (whatever it is) only once. But up to 150 users can get in on it kind of thing. That's simply a two step problem. 1) filter the people who can access the link (only approved members); 2) then have the protected link be tied to a script that monitors the download count for that member. It should be easy enough to create a table for each member having their logon id, password, and download count for whatever item you want to restrict download. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] File Downloads
The users will have gone through a registration and login to get to the downloads. The files will be served from MySQL and output to HTML of Flash. This is for a small project of limited edition audio or pictures or scripts, etc. Hens, "I'd like" to limit each user in the allotted 150 to be able to download (whatever it is) only once. But up to 150 users can get in on it kind of thing. Karl On May 28, 2010, at 4:41 PM, Karl DeSaulniers wrote: On May 28, 2010, at 4:25 PM, tedd wrote: At 3:39 PM -0500 5/28/10, Karl DeSaulniers wrote: Hello, How can I go about restricting the number of downloads of a file on my server? For Eg: if I want a music track to only be able to be downloaded by 150 people and thats it.. ever, how can I go about doing this? Much obliged, Karl DeSaulniers Karl: Just have the download pass through a script that counts, such as found here: http://sperling.com/freeware.php When someone click the link, it activates a script that provides the download and saves a count. It would be trivial to stop the download at a specific number. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Hey thanks Tedd. Quick question. Were you referring me to this link to download one of their demos or just to show that they count their downloads? EG: Binary-Tree v1.1 Downloads: 2806 THX Karl DeSaulniers Design Drumm http://designdrumm.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Karl DeSaulniers Design Drumm http://designdrumm.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] File Downloads
On May 28, 2010, at 4:25 PM, tedd wrote: At 3:39 PM -0500 5/28/10, Karl DeSaulniers wrote: Hello, How can I go about restricting the number of downloads of a file on my server? For Eg: if I want a music track to only be able to be downloaded by 150 people and thats it.. ever, how can I go about doing this? Much obliged, Karl DeSaulniers Karl: Just have the download pass through a script that counts, such as found here: http://sperling.com/freeware.php When someone click the link, it activates a script that provides the download and saves a count. It would be trivial to stop the download at a specific number. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Hey thanks Tedd. Quick question. Were you referring me to this link to download one of their demos or just to show that they count their downloads? EG: Binary-Tree v1.1 Downloads: 2806 THX Karl DeSaulniers Design Drumm http://designdrumm.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] File Downloads
At 3:39 PM -0500 5/28/10, Karl DeSaulniers wrote: Hello, How can I go about restricting the number of downloads of a file on my server? For Eg: if I want a music track to only be able to be downloaded by 150 people and thats it.. ever, how can I go about doing this? Much obliged, Karl DeSaulniers Karl: Just have the download pass through a script that counts, such as found here: http://sperling.com/freeware.php When someone click the link, it activates a script that provides the download and saves a count. It would be trivial to stop the download at a specific number. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] File Downloads
On May 28, 2010, at 3:54 PM, Marc Guay wrote: How can I go about restricting the number of downloads of a file on my server? Something like this could be triggered every time and then you can do whatever you want once it hits 150... maybe have it send you an email notification or something... http://www.stevedawson.com/article0007.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Very interesting link. Thank you for sharing. Not sure how this could be tied into what I'm trying for. Would I add this to the function that did the downloading of the file? Best, Karl DeSaulniers Design Drumm http://designdrumm.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] File Downloads
> How can I go about restricting the number of downloads of a file on my > server? Something like this could be triggered every time and then you can do whatever you want once it hits 150... maybe have it send you an email notification or something... http://www.stevedawson.com/article0007.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] File downloads
At 7:47 AM + 6/8/06, kartikay malhotra wrote: >New problem: >Is there a way for the server to notify the client that a new file has >become available for download, provided the client was online in the past X >minutes? > >This could be done... kartikay: First, it's probably best if you start a new thread for a new subject. Second, it might be better for you to state what you would like to do rather than set the specifics of how it is to be done, understand? Simply put, why are you trying to do? tedd -- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] File downloads
Thanks to Tedd, Barry, George and others for help over "download file" problem. I'm going to receive an ACK if the file downloads correctly. In absence of such an ACK, a script would quitely remove the temporary files after a fixed interval of time. Temporary files have unique filenames. New problem: Is there a way for the server to notify the client that a new file has become available for download, provided the client was online in the past X minutes? This could be done if 1. The client queries the server after a set interval of time. I DO NOT WANT THIS FOR SOME SILLY REASON. 2. The connection is kept alive (?). With my current knowledge of PHP, I am not able to manage this. Cookies or sessions? Can't find a related example directly dealing with this issue. All wild ideas/links/examples are welcome. What changes would be required in Apache conf file (if any)? Thanks & Regards KM On 6/7/06, tedd <[EMAIL PROTECTED]> wrote: At 8:42 AM + 6/7/06, kartikay malhotra wrote: >Dear All, > >I have a HTTP server + MySQL database. Everytime a file is requested for >download, my PHP script loads the content from the database into a temporary >file (on the server). I then pass a URL to the client, with a link to this >file. The client can thus download the file at any time. > >However, I can foresee many problems with this approach. One is, when to >delete the temporary file? Also with more than one client, this approach >would have to be refined. Security is also an issue: One user may read >another's files. > >Can anyone kindly give me an alternative approach? > >I reiterate, I cannot supply static URLs as the downloadable file is >generated on-demand. > >Thanks & Regards >KM KM: Thinking off the top of my head (not always the best for me) -- why not give the user a static url AND a key? The static url would have a php program sitting there waiting for a user to come along and provide the correct key. After which, your program would then create the file (in a random named folder); provide the user with a link; and clean-up after he's done. That way you have the control over what's happening. The key approach handles security and when to clean-up. hth's tedd -- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] File downloads
At 8:42 AM + 6/7/06, kartikay malhotra wrote: >Dear All, > >I have a HTTP server + MySQL database. Everytime a file is requested for >download, my PHP script loads the content from the database into a temporary >file (on the server). I then pass a URL to the client, with a link to this >file. The client can thus download the file at any time. > >However, I can foresee many problems with this approach. One is, when to >delete the temporary file? Also with more than one client, this approach >would have to be refined. Security is also an issue: One user may read >another's files. > >Can anyone kindly give me an alternative approach? > >I reiterate, I cannot supply static URLs as the downloadable file is >generated on-demand. > >Thanks & Regards >KM KM: Thinking off the top of my head (not always the best for me) -- why not give the user a static url AND a key? The static url would have a php program sitting there waiting for a user to come along and provide the correct key. After which, your program would then create the file (in a random named folder); provide the user with a link; and clean-up after he's done. That way you have the control over what's happening. The key approach handles security and when to clean-up. hth's tedd -- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] file downloads
View your Apache logs after doing these mods, just in case the database has died after your testing that worked: It's also good to have these lines stay in there so you can debug later... > mysql_connect("localhost","user","pass"); ... or error_log(0, "Could not connect to database in " . __FILE__ . ":" . __LINE__); > mysql_select_db("db"); ... or error_log(0, "Could not select db in " . __FILE__ . ":" . __LINE__); > $query = "SELECT file_path from photos where photos_id=$photos_id"; > $result = @mysql_query($query); ... or error_log(0, "Could not exec $query in " . __FILE__ . ":" . __LINE__); > $row = mysql_fetch_row($result); > $path = $row[0]; > $file_name = basename($path); > file://print ""; > file://print "$file_name"; > > header("Content-Type: application/download\n"); Why are you adding a \n there? That pretty much pukes the rest of the headers, since it's a newline you've forced in, and now the other stuff is part of the data, not the headers... Also, use application/octet-stream for download, I think. > header("Content-Disposition: attachment; filename=$file_name"); > header("Content-Transfer-Encoding: binary"); Is this the full path or a relative path? I never trust relative paths when it comes to file-system operations. But I have a low trust-value in computers, software, and life in general. :-) > readfile($path); > > ?> > > This should work shouldn't it? If you did it right, it would work. :-) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] file downloads
Hi I'm very news in php Anyone knows how can i submit sample HTML form by php and write into database ??? I have anly one registration form username, password, First name last_name, and phone I need only small samples and all will be ok .. thanks in advance = - Original Message - From: "Data Driven Design" <[EMAIL PROTECTED]> To: "Rasmus Lerdorf" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Saturday, August 04, 2001 10:27 PM Subject: Re: [PHP] file downloads > I usually put or die(mysql_error()) and make it work before I put in the @, > that's been done already. This will display the image > > $result = @mysql_query($query); > $row = mysql_fetch_row($result); > $path = $row[0]; > print ""; > > What I want is to display a 'save as' box to download the image whose file > path is stored in the variable $path. Am I doing something wrong in the > header section? The print statement would be commented out if I used this. > > $file_path = basename($path); > header("Content-Type: application/download\n"); > header("Content-Disposition: attachment; filename=$file_name"); > header("Content-Transfer-Encoding: binary"); > readfile($path); > > Data Driven Design > 1506 Tuscaloosa Ave > Holly Hill, Florida 32117 > > http://www.datadrivendesign.com > Phone: (386) 226-8979 > > Websites That WORK For You > - Original Message ----- > From: "Rasmus Lerdorf" <[EMAIL PROTECTED]> > To: "Data Driven Design" <[EMAIL PROTECTED]> > Cc: <[EMAIL PROTECTED]> > Sent: Saturday, August 04, 2001 1:01 PM > Subject: Re: [PHP] file downloads > > > > > I made the changes you suggested and it's still a no go. I'm sure of the > > > query because > > > > > > print ""; > > > > > > Will display the image I'm trying to download. > > > > How does that make the SQL query valid? You didn't implement the > > mysql_query() error checking I suggested. That's likely what is causing > > you problems. > > > > -Rasmus > > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] _ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] file downloads
I usually put or die(mysql_error()) and make it work before I put in the @, that's been done already. This will display the image $result = @mysql_query($query); $row = mysql_fetch_row($result); $path = $row[0]; print ""; What I want is to display a 'save as' box to download the image whose file path is stored in the variable $path. Am I doing something wrong in the header section? The print statement would be commented out if I used this. $file_path = basename($path); header("Content-Type: application/download\n"); header("Content-Disposition: attachment; filename=$file_name"); header("Content-Transfer-Encoding: binary"); readfile($path); Data Driven Design 1506 Tuscaloosa Ave Holly Hill, Florida 32117 http://www.datadrivendesign.com Phone: (386) 226-8979 Websites That WORK For You - Original Message - From: "Rasmus Lerdorf" <[EMAIL PROTECTED]> To: "Data Driven Design" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Saturday, August 04, 2001 1:01 PM Subject: Re: [PHP] file downloads > > I made the changes you suggested and it's still a no go. I'm sure of the > > query because > > > > print ""; > > > > Will display the image I'm trying to download. > > How does that make the SQL query valid? You didn't implement the > mysql_query() error checking I suggested. That's likely what is causing > you problems. > > -Rasmus > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] file downloads
> I made the changes you suggested and it's still a no go. I'm sure of the > query because > > print ""; > > Will display the image I'm trying to download. How does that make the SQL query valid? You didn't implement the mysql_query() error checking I suggested. That's likely what is causing you problems. -Rasmus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] file downloads
I made the changes you suggested and it's still a no go. I'm sure of the query because print ""; Will display the image I'm trying to download. This is my environment. PHP Version 3.0.16 Apache/1.3.3 Cobalt safe_mode 1 "; //print "$file_name"; header("Content-Type: application/download\n"); header("Content-Disposition: attachment; filename=$file_name"); header("Content-Transfer-Encoding: binary"); readfile($path); ?> This should work shouldn't it? - Original Message - From: "Rasmus Lerdorf" <[EMAIL PROTECTED]> To: "Data Driven Design" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Saturday, August 04, 2001 11:57 AM Subject: Re: [PHP] file downloads > > Why does this code produce a page cannot be displayed error? > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] file downloads
> Why does this code produce a page cannot be displayed error? Your query is probably wrong. Comment out the header stuff and add some error checking to your query. > mysql_connect("localhost","username","password"); > mysql_select_db("database"); > $query = "SELECT file_path from photos where photos_id=$photos_id"; > $result = @mysql_query("$query"); The quotes are useless there. Change the above to: $result = mysql_query($query) or die(mysql_error()); > $row = mysql_fetch_row($result); > $path = $row[0]; > $parts = split("/",$path); Use explode() instead. No sense wasting a regex on a trivial delimiter like that. > $file_name = $parts[count($parts)-1]; uh.. basename() would do the same thing, so you can get rid of this line and also the split/explode actually. > header("Content-Type: application/download\n"); > header("Content-Disposition: attachment; filename=$file_name"); > header("Content-Transfer-Encoding: binary"); > $fn=fopen($path , "r"); > fpassthru($fn); readfile($path); would replace those two lines. -Rasmus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]