By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,452 Members | 974 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,452 IT Pros & Developers. It's quick & easy.

How to rename file for each download request

P: 13
ok here is what Im trying to create:
simple code that renames the file to be downloaded each time someone downloads it.
example:
you download my file, it will be rename to smth different that way you cant access the file using that URL anymore

here is the code:
for some reasons the renaming part doesnt work.
any input would be greatly appreciated
as122223333443.txt = the new generated name is updated to this file that way the next person to download gets the right link.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. function renom($file1, $file2)
  3. {
  4.     rename($file1, $file2);
  5.     }
  6. function updateit()
  7. {
  8.     $random_digit=rand(0000,9999);
  9.     $random_link = $random_digit.".zip";
  10.     $myFile = "as122223333443.txt";
  11. $fh = fopen($myFile, 'w') or die("can't open file");
  12. $stringData = $random_link;
  13. fwrite($fh, $stringData);
  14. fclose($fh);
  15. $file1 = $thelink;
  16. $file2 = $random_link;
  17. renom($file1,$file2);
  18.     }
  19. function downloada()
  20. {
  21.     $dlink = "as122223333443.txt";
  22. $fh = fopen($dlink, 'r');
  23. $thelink= fread($fh, 25);
  24. fclose($fh);
  25.  
  26. echo "http://www.site.com/".$thelink;
  27.     updateit();
  28.     }
Jun 1 '10 #1
Share this Question
Share on Google+
1 Reply


JKing
Expert 100+
P: 1,206
@fogsys
Your variable $thelink is invisible to your function updateit. I suggest passing your $thelink variable to your updateit function.
Jun 1 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.