Jump to content

Reeksy

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

About Reeksy

  • Birthday 04/10/1985

Contact Methods

  • MSN
    reeksyno9@hotmail.com

Profile Information

  • Gender
    Male
  • Location
    Somerset, UK

Reeksy's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi again. I have managed to achieve the capping of the download speed. If anyone’s interested I changed the max_execution_time directive at runtime to stop the download from stopping after 30 seconds (due to the loop). 30 seconds if the max_execution_time directive default in the ini file. What I’m unsure of now is how to notify a user that they cannot download another file whilst the current one is in progress. The issue is; when a download is in progress and you try and access the script the page will appear as if it’s timed-out. This is obviously because the loop within the script is still running. Although this affectively does stop someone from downloading two files at the same time it doesn’t look very professional! I ideally want a message saying 'Can’t download as download in progress'. To do this logging the user's IP in a session seems like a good idea. I’ve tried to include this logic within the script, however when you access the page whilst a download is in progress the loop is still active, so the script wont re-run until the download has finished! Thus no message is displayed! I’ve included the script below for reference. Any help would be great // Session start session_start(); session_name('downloadTest'); // Check to see if the user has a download in progress already if (isset($_SESSION[$_SERVER['REMOTE_ADDR']])) { print 'You already have a download in progress'; exit(); } // Check passed, continue to download file... // Set the max_execution_time. 1 year so downloads don't time out! ini_set('max_execution_time', 31536000); // local file that should be send to the client $local_file = 'file2.exe'; // filename that the user gets as default $download_file = 'your-download-name.zip'; // set the download rate limit (=> 2,5 kb/s) $download_rate = 20.5; if(file_exists($local_file) && is_file($local_file)) { // send headers header('Cache-control: private'); header('Content-Type: application/octet-stream'); header('Content-Length: '.filesize($local_file)); header('Content-Disposition: filename='.$download_file); // flush content flush(); // Set the session marker $_SESSION[$_SERVER['REMOTE_ADDR']] = true; // open file stream $file = fopen($local_file, "r"); while(!feof($file)) { // send the current file part to the browser print fread($file, round($download_rate * 1024)); // flush the content to the browser flush(); // sleep one second sleep(1); } // close file stream fclose($file); // Unset session marker as download complete unset($_SESSION[$_SERVER['REMOTE_ADDR']]); }else{ die('Error: The file '.$local_file.' does not exist!'); } Regards.
  2. OK thanks - very helpful. I'll give this method a try. Regards Jon.
  3. Hi I'm having trouble! What i ultimately want is for each user on my site to be capped with a (maximum) 2Kb per second download transfer rate and only be able to download one file at a time. Therefore i need to know when a user has a download in progress. So, if they try and download 2 or more files at the same time i can block them. I don't have much idea of how to achieve this with PHP and Apache! Can anyone point me in the right direction. Regards Jon
  4. Job Done! Ok thanks a lot guys. Much appreciated. I'm sure I'll be back soon! Jon
  5. [quote author=rajmohan link=topic=110671.msg447951#msg447951 date=1160137784] can you please tell me for what it will be use?? i mean i which situation you are using this please tell me [/quote] OK the scenario is: I have a link on my website, this link fires off to a map on an external website. However this external map service requires the coordinates of the item you’re looking at. The coordinates are specific to an item and can change so ideally they need to be dynamically pulled out. My problem is I don’t have the coordinates to pull out dynamically. Therefore I need to copy the exact link from another website which does have the up-to-date coordinates. So I need to get a line of code from their source code. I can get the contents using file_get_contents() I just need to know how to find the line where that link is and return it. I wont always know the line number but I do know the name of the link (which only appears once within the source code) Hope that makes sense!
  6. The file would never be bigger than 100K. Usually around 50K. Does that help!?
  7. OK thanks. Problem is i don't always know the line number! However i do know the text string. Is it possible to search the file for an instance of that text string?
  8. Hi I have a line of code within a text file. Is it possible to search the file for that line of code and then return it? Jon
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.