MilesWilson Posted July 14, 2006 Share Posted July 14, 2006 Hello!Can anyone help me with this? I want to be able to count the number of files in an uploaded zip file.I have this code:[code]<?php$zip = zip_open("images.zip");/* At this point I would like to echo another peice of javascript, telling the parent how many files there are in the zip */if ($zip) { while ($zip_entry = zip_read($zip)) { if (zip_entry_open($zip, $zip_entry, "r")) { $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); $name = zip_entry_name($zip_entry); $stream = fopen('images/'.$name, "w"); fwrite($stream, $buf) or die("helllp!"); zip_entry_close($zip_entry); echo "<script language='javascript'> window.parent.displayImage('".$name."'); </script>"; ob_flush(); flush(); sleep(3); } } zip_close($zip);}?>[/code]The sleep(3) is there to replace the code I will write shortly, which resizes the image. In the meantime, sleep() means I get a simulation of the time passing.Thanks in advance.Miles Quote Link to comment https://forums.phpfreaks.com/topic/14596-counting-the-number-of-files-in-a-zip-file/ Share on other sites More sharing options...
vidyashankara Posted July 14, 2006 Share Posted July 14, 2006 You could do this another way, if the script is running on linux[code]$command = "tar -tvf $file > file.output"system ($command, $output);$lines = file(file.output);$num_lines = count ($lines);echo "The Zip file has $num_lines lines";[/code]easy :) Quote Link to comment https://forums.phpfreaks.com/topic/14596-counting-the-number-of-files-in-a-zip-file/#findComment-58031 Share on other sites More sharing options...
vidyashankara Posted July 14, 2006 Share Posted July 14, 2006 This works only on tar files, If you want it for a zip file, just use a command to list the files in the zip file in the $command statement instead! Quote Link to comment https://forums.phpfreaks.com/topic/14596-counting-the-number-of-files-in-a-zip-file/#findComment-58044 Share on other sites More sharing options...
MilesWilson Posted July 15, 2006 Author Share Posted July 15, 2006 Cheers. Didn't think of running the systems unzipping functions.ThanksM Quote Link to comment https://forums.phpfreaks.com/topic/14596-counting-the-number-of-files-in-a-zip-file/#findComment-58412 Share on other sites More sharing options...
agaul Posted December 23, 2006 Share Posted December 23, 2006 [quote author=vidyashankara link=topic=100577.msg397178#msg397178 date=1152899863]This works only on tar files, If you want it for a zip file, just use a command to list the files in the zip file in the $command statement instead![/quote]and what exactly would that command be? I'm not fluent with Linux at all. Quote Link to comment https://forums.phpfreaks.com/topic/14596-counting-the-number-of-files-in-a-zip-file/#findComment-146941 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.