Simple Explorer
A simple explorer clone. It is heavily commented and shows you a way to show alpha-blended icons, extract icons based on extension or from files themselves, a simple (or recursive) way to collect information about drives and folder, and some other useful stuff for the in-experienced vb.net programmer.
AI
Riepilogo AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Codice sorgente
Upload
<p>I was given a task to restrict number of downloads , divide the total bandwidth into 2 groups and control the speed of the downloads. So i came up with the idea of doing it with PHP cause mod_bandwidth or mod_throttle werent tailored for the job. Here is the part where i attempt to control the speed of the download.
<code><font color="#000000">
<font color="#0000BB"><br>
<br>
<br>
<? <br />
$filedownload </font><font color="#007700">= </font><font color="#DD0000">"files/abc.exe"</font><font color="#007700">;
<br />
</font><font color="#0000BB">$time </font><font color="#007700">= </font><font color="#0000BB">10000</font><font color="#007700">;
<br />
</font><font color="#0000BB">$obytes </font><font color="#007700">= </font><font color="#0000BB">150</font><font color="#007700">*</font><font color="#0000BB">1024</font><font color="#007700">; </font><font color="#FF8000">//150k download speed restriction
<br />
</font><font color="#0000BB">$fd </font><font color="#007700">= </font><font color="#0000BB">fopen </font><font color="#007700">(</font><font color="#0000BB">$filedownload</font><font color="#007700">, </font><font color="#DD0000">"rb"</font><font color="#007700">);
<br />
while (!</font><font color="#0000BB">feof </font><font color="#007700">(</font><font color="#0000BB">$fd</font><font color="#007700">)) {
<br />
list(</font><font color="#0000BB">$usec</font><font color="#007700">, </font><font color="#0000BB">$sec</font><font color="#007700">) = </font><font color="#0000BB">explode</font><font color="#007700">(</font><font color="#DD0000">" "</font><font color="#007700">, </font><font color="#0000BB">microtime</font><font color="#007700">());
<br />
</font><font color="#0000BB">$time_start </font><font color="#007700">= </font><font color="#0000BB">$usec </font><font color="#007700">+ </font><font color="#0000BB">$sec</font><font color="#007700">;
<br />
</font><font color="#0000BB">$bytes </font><font color="#007700">= </font><font color="#0000BB">ceil</font><font color="#007700">(</font><font color="#0000BB">$obytes</font><font color="#007700">/</font><font color="#0000BB">100</font><font color="#007700">);
<br />
echo </font><font color="#0000BB">fread</font><font color="#007700">(</font><font color="#0000BB">$fd</font><font color="#007700">, </font><font color="#0000BB">$bytes</font><font color="#007700">);
<br />
</font><font color="#0000BB">flush</font><font color="#007700">();
<br />
<br />
if(</font><font color="#0000BB">$time </font><font color="#007700">< </font><font color="#0000BB">10000</font><font color="#007700">) </font><font color="#0000BB">usleep</font><font color="#007700">(</font><font color="#0000BB">10000</font><font color="#007700">-</font><font color="#0000BB">$time</font><font color="#007700">);
<br />
</font><font color="#0000BB">$i</font><font color="#007700">++;
<br />
list(</font><font color="#0000BB">$usec</font><font color="#007700">, </font><font color="#0000BB">$sec</font><font color="#007700">) = </font><font color="#0000BB">explode</font><font color="#007700">(</font><font color="#DD0000">" "</font><font color="#007700">, </font><font color="#0000BB">microtime</font><font color="#007700">());
<br />
</font><font color="#0000BB">$time_end </font><font color="#007700">= </font><font color="#0000BB">$usec </font><font color="#007700">+ </font><font color="#0000BB">$sec</font><font color="#007700">;
<br />
</font><font color="#0000BB">$time </font><font color="#007700">=</font><font color="#0000BB">ceil</font><font color="#007700">((</font><font color="#0000BB">$time_end </font><font color="#007700">- </font><font color="#0000BB">$time_start</font><font color="#007700">)*</font><font color="#0000BB">1000000</font><font color="#007700">)+</font><font color="#0000BB">10</font><font color="#007700">;
<br />
}
<br />
</font><font color="#0000BB">fclose </font><font color="#007700">(</font><font color="#0000BB">$fd</font><font color="#007700">);
<br />
</font><font color="#0000BB">?></font>
</font> </code><br>
<br>Basically we know how many max bytes we need to send per sec , so we calculate the time in microseconds it took for the code iteration to take place and deduct that time from 1 sec and usleep it for that long , if it took more than 1 sec to complete the iteration ( for example the user is on dialup and cannt receive 150k per sec) than dont put in the delay. <br>
<br>
Hope this helps someone. You can find more PHP tips on my site but this one had to be shared in a better way :)
</p>
Commenti originali (3)
Recuperato da Wayback Machine