0

Hello.

Ive got this small script which caches a web page. It names the file with a unique ID which is all fine but I need it to name it with the unique ID but with a HTML extention.

How would I do this?

Heres my script...

<?php
$page = file_get_contents('http://www.google.com');

$num = md5(uniqid());

$filename = $num;

file_put_contents($filename,$page);

?>
2
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by !Unreal
0

Thank you. I managed to solve the problem but you did pretty much the same thing.

Thanks for the reply :)

0

Why not replace the random meaningless filename of

$num = md5(uniqid());

with a unix timestamp which will record the files in chronological order and still be unique:

$num = date("Ymd his");
$filename = $num." ".md5(uniqid(rand(), true)).".html";

?
This way you would know exactly when each file was written.

0

Seems like a better idea. Atleast I wont have any risk of getting two identical file names.

Thanks.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.