943,928 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 828
  • PHP RSS
Dec 21st, 2008
0

UniqueID.html

Expand Post »
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 Syntax (Toggle Plain Text)
  1. <?php
  2. $page = file_get_contents('http://www.google.com');
  3.  
  4. $num = md5(uniqid());
  5.  
  6. $filename = $num;
  7.  
  8. file_put_contents($filename,$page);
  9.  
  10. ?>
Last edited by !Unreal; Dec 21st, 2008 at 10:50 pm.
Similar Threads
Reputation Points: 11
Solved Threads: 2
Junior Poster
!Unreal is offline Offline
112 posts
since Dec 2007
Dec 21st, 2008
1

Re: UniqueID.html

php Syntax (Toggle Plain Text)
  1. <?php
  2. $page = file_get_contents('http://www.google.com');
  3. $num = md5(uniqid());
  4. $filename = $num;
  5. $filename .=".html";
  6. $handle=fopen($filename,"x+");
  7. fwrite($handle,$page);
  8. ?>
Last edited by buddylee17; Dec 21st, 2008 at 11:58 pm.
Reputation Points: 232
Solved Threads: 137
Practically a Master Poster
buddylee17 is offline Offline
665 posts
since Nov 2007
Dec 22nd, 2008
0

Re: UniqueID.html

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

Thanks for the reply
Reputation Points: 11
Solved Threads: 2
Junior Poster
!Unreal is offline Offline
112 posts
since Dec 2007
Dec 22nd, 2008
0

Re: UniqueID.html

Why not replace the random meaningless filename of
php Syntax (Toggle Plain Text)
  1. $num = md5(uniqid());
with a unix timestamp which will record the files in chronological order and still be unique:
php Syntax (Toggle Plain Text)
  1. $num = date("Ymd his");
  2. $filename = $num." ".md5(uniqid(rand(), true)).".html";
?
This way you would know exactly when each file was written.
Reputation Points: 232
Solved Threads: 137
Practically a Master Poster
buddylee17 is offline Offline
665 posts
since Nov 2007
Dec 22nd, 2008
0

Re: UniqueID.html

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

Thanks.
Reputation Points: 11
Solved Threads: 2
Junior Poster
!Unreal is offline Offline
112 posts
since Dec 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: PHP FORM without senders email address
Next Thread in PHP Forum Timeline: Need Some Help With This Script





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC