Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

$unlink file wildcards & directories

Status
Not open for further replies.

TsunamiHype

Programmer
Feb 18, 2005
4
US
scenario is this...a customer #1 uploads a file to a directory they create via a unique codeword. The codeword becomes a directory and all files they upload are stored here.

Customer #2 logs into a download page and enters customer #1's codeword. he is then directed to the specific folder and can grab the files. Upon completion, click "confirm" to notify customer #1 that the files have been downloaded (via email)

easy nuff really, but...
Now, at this time I need to open tmp/[$codeword] and delete all files & then rmdir with no knowledge of the file names or the directory name [$codeword]. Keeping in mind that there may be multiple users saving in /tmp at any given time

i hope this isn't too vague... but to save space I won't include existing scripts unless neccessary.



I was going along the lines of :

$path = "/var/
// Open the folder
$dir_handle = @opendir($path) or die("<center><font color=#FF0000><font size=4>please check your codeword");

foreach (glob("*.wmf") as $file) {
echo "$filename size " . filesize($file) . "\n";
unlink($file);
}
--------timeline--------
//upload.htm - input form to gain $codeword
//upload.php - mkdir tmp/[$codeword] stores files here
//confirm.php - confirms file upload and size (need to have $unlink script here)

2 issues: 1.
$codeword is posted to upload.php from upload.htm and I am trying to do this without cookie usage.
2. (glob("*.wmf") assumes its a wmf... hell it could be an itunes file for all i know

any ideas of course are greatly needed....
 
on completion of the download, a simple "confim" button will email user 1 and trigger the deletion
 
issues:
1. $codeword is posted. You need no cookies.
2. What's the business about not knowing the $codeword after the person downloads the files?
How are you presenting the files for download - just a directory listing or a generated page with download links?
In the generated page you would just store the codeword in a hidden variable and then post the form with the confirm button (which sends the codeword) and so you can remove the entire folder.

All this said - I would not be comfortable to have a deletion mechanism that can be accessed that way.
 
$codeword is posted not to the confirm page, but rather the download.php for directory creation. This was a system that a company wanted for internal file transfers between only 2 employees. They are interested in sending a file from one of their houses to remote location for the other person to pickup, but want to limit the amount of access for 1 employee to only have the rights to download but never have more rights than is neccessary...all from .htaccess pages of course. Out of curiosity, how would you tackle the deletion ??
 
I agree with DRJ478 in being leery of deletion mechanisms that don't require explicit human activation.

I would have a management console for each user. A user uploads a particular file, which is stored on the filesystem and given a code stamp. The original filename and the codestamp would be stored in a database. That information would appear with the file in the user's management interface.

A user could then give the code stamp to another user, who could then download the associated file, either from within his own management console or simply by pointing his browser to a URL like: [ignore][/ignore]. When the file is downloaded, PHP script that streams the file out to the recipient could then update the database, indicating that the file had been downloaded. It could also send the poster an email that the file had been accessed.

The posting user could then, from his management interface, delete the file. The file would be removed from the filesystem, and the file's associated record would be removed from the database.

One "gotcha" is to make sure that you don't assign files sequential code stamps. This would make it too easy for a user to guess other filenames.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
great input guys. Thanks for all the quick responses. I'll let ya know how it goes
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top