UniqueID.html

Reply

Join Date: Dec 2007
Posts: 112
Reputation: !Unreal is an unknown quantity at this point 
Solved Threads: 2
!Unreal's Avatar
!Unreal !Unreal is offline Offline
Junior Poster

UniqueID.html

 
0
  #1
Dec 21st, 2008
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...

  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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 596
Reputation: buddylee17 has a spectacular aura about buddylee17 has a spectacular aura about 
Solved Threads: 125
buddylee17's Avatar
buddylee17 buddylee17 is offline Offline
Posting Pro

Re: UniqueID.html

 
1
  #2
Dec 21st, 2008
  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.
Lost time is never found again.
- Benjamin Franklin
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 112
Reputation: !Unreal is an unknown quantity at this point 
Solved Threads: 2
!Unreal's Avatar
!Unreal !Unreal is offline Offline
Junior Poster

Re: UniqueID.html

 
0
  #3
Dec 22nd, 2008
Thank you. I managed to solve the problem but you did pretty much the same thing.

Thanks for the reply
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 596
Reputation: buddylee17 has a spectacular aura about buddylee17 has a spectacular aura about 
Solved Threads: 125
buddylee17's Avatar
buddylee17 buddylee17 is offline Offline
Posting Pro

Re: UniqueID.html

 
0
  #4
Dec 22nd, 2008
Why not replace the random meaningless filename of
  1. $num = md5(uniqid());
with a unix timestamp which will record the files in chronological order and still be unique:
  1. $num = date("Ymd his");
  2. $filename = $num." ".md5(uniqid(rand(), true)).".html";
?
This way you would know exactly when each file was written.
Lost time is never found again.
- Benjamin Franklin
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 112
Reputation: !Unreal is an unknown quantity at this point 
Solved Threads: 2
!Unreal's Avatar
!Unreal !Unreal is offline Offline
Junior Poster

Re: UniqueID.html

 
0
  #5
Dec 22nd, 2008
Seems like a better idea. Atleast I wont have any risk of getting two identical file names.

Thanks.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC