473,322 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

How to rename file for each download request

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
1 2335
JKing
1,206 Expert 1GB
@fogsys
Your variable $thelink is invisible to your function updateit. I suggest passing your $thelink variable to your updateit function.
Jun 1 '10 #2

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

Similar topics

5
by: Brandon Walters | last post by:
I wrote a file download module for my website. The reason for the file download module is that my website downloads work on a credit based system. So I need to keep track of and limit daily...
2
by: andrewcw | last post by:
Is there a simpler way to rename a file other than copy the source file to the target file, then deleting the source file ? { i did not see any rename in the File class )
0
by: jmd | last post by:
Hello. I want to write a C# program that does completely automatically what, until now, I do manually, witch is describe below : 1. I launch IE (6) 2. I browse to my desired download page, say...
0
by: Buddy Ackerman | last post by:
I am trying to implment a file download via a link such that when clicked, instead of starting the default application for that type of file the user will be presented with a download dialog...
0
by: Rhys666 | last post by:
Basically I have a link that opens my download page and the querystring identifies the type of 'template' Excel spreadsheet has asked to download. The download page reads the querystring,...
2
by: Bruce Russell | last post by:
This may sound stupid but I can't rename the WebForm1.aspx in the solution explorer. The file is located in my local web server at C:\Inetpub\wwwroot\Lab3-VB-Starter\WebForm1.aspx Is there...
18
by: jmd | last post by:
Hello, I posted the following in the C# forum but without one answer. But perhaps now in vb.net someone has some guidelines ! This is my question : I want to write a vb.net program that does...
3
by: tshad | last post by:
I have a function that downloads a file to the users computer and it works fine. The problem is that I then want the program to rename the file (file.move) to the same name plus todays date. ...
0
by: aris1234 | last post by:
how to rename file name in DB..??? this my code, but this code only save image to folder, can't rename file in DB : <?php //Сheck that we have a file $folder = "../property/$spid";...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.