asaschool Posted March 28, 2008 Share Posted March 28, 2008 Hey everyone, I have a problem with trying to open a zip file that has a changing name. The file always starts with the same first 4 letters and an underscore followed by 4 random letters or numbers and always ends in .zip: Example: FILE_DG01.zip - Today FILE_9044.zip - Tomorrow FILE_809P.zip - Next Day........ I use the following simple script to extract the files and move them to another directory where I use them in my applications: <?php $zip = zip_open("FILENAME.zip"); if ($zip) { while ($zip_entry = zip_read($zip)) { $fp = fopen("DIRECTORY".zip_entry_name($zip_entry), "w"); if (zip_entry_open($zip, $zip_entry, "r")) { $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); fwrite($fp,"$buf"); zip_entry_close($zip_entry); fclose($fp); } } zip_close($zip); } ?> I have looked everywhere for an answer and I am sure that I am looking in the wrong places for the solution to this. Any help is appreciated. Thanks Link to comment https://forums.phpfreaks.com/topic/98246-opening-a-file-with-a-partially-known-filename/ Share on other sites More sharing options...
mb81 Posted March 28, 2008 Share Posted March 28, 2008 Why are the last 4 digits a random set of letters, why you don't label it with a date code (like 032708) Link to comment https://forums.phpfreaks.com/topic/98246-opening-a-file-with-a-partially-known-filename/#findComment-502732 Share on other sites More sharing options...
asaschool Posted March 28, 2008 Author Share Posted March 28, 2008 That would be easier. I dont label the files I just access and use them. I was told that the server generates these names. I log on to a third-party server and extract files to use in some of my applications. The main file is labeled with a date but the files inside all conform to the random name. All the files are identifiable and conform the following name structure: FILE_XXXX.zip Link to comment https://forums.phpfreaks.com/topic/98246-opening-a-file-with-a-partially-known-filename/#findComment-502733 Share on other sites More sharing options...
doni49 Posted March 28, 2008 Share Posted March 28, 2008 I'm confused. Is it the zip file with the random name? Or is it the files INSIDE the zip file that have random names? What files are you trying to process? If you're trying to process the zip file, how are the zip files retrieved? Are YOU retrieving them from this third party server? Does one of YOUR scripts retrieve them form the other server? If the script is being retrieved by you or your script, you could give it whatever name you wanted. Link to comment https://forums.phpfreaks.com/topic/98246-opening-a-file-with-a-partially-known-filename/#findComment-502747 Share on other sites More sharing options...
asaschool Posted March 28, 2008 Author Share Posted March 28, 2008 ok, sorry I need to explain this better. What I need to do is copy files located on a remote FTP server and move them to my local server. When I move these files I rename them and place them in their proper directories. I already have a script that executes this. Inside of the files I moved to the local server are four zip files that have the random names and all of them need to be unzipped. All of them start with a unique title followed by _ and the four random digits. There is no rhyme or reason to the random digits. Is there a way to unzip all of the files inside the file that I moved to the local server in one script? If so should I use a foreach statement? I'm using the code I entered earlier to unzip specific files but it will not unzip a directory full of zips. Example: remote_file.zip------file copied and moved---->renamed_file_on_local.zip (this is completed and working) contents of: renamed_file_on_local.zip FILE1_XXXX.zip------file copied and moved--->unzipped (I can do this if the zip name is known, but it changes daily) FILE2_XXXX.zip FILE3_XXXX.zip FILE4_XXXX.zip contents of: zipX.zip files i need Thanks again for all your input Link to comment https://forums.phpfreaks.com/topic/98246-opening-a-file-with-a-partially-known-filename/#findComment-502775 Share on other sites More sharing options...
doni49 Posted March 28, 2008 Share Posted March 28, 2008 That helps. When you unzip the first file, put the four files in a folder that has NO OTHER files or sub-folders. Then read the folder and get a list of files in that folder. You can see an example of opening a folder and getting a list of its files at www.php.net/opendir. Link to comment https://forums.phpfreaks.com/topic/98246-opening-a-file-with-a-partially-known-filename/#findComment-502985 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.