serious1234 Posted July 25, 2009 Share Posted July 25, 2009 I have a script that put a file in zip archive and make it available for download. my problem is that when i download those zipped files they come with number.. for example my file is something like avenging.srt and when it becomes avenging.[1].srt.zip . everything is ok but my problem is with the dot before the file extension srt. Everytime i download the same file it changes to the same name with different number like avenging[2].srt.zip , avenging[3].srt.zip and when i use a name without extension like avenging it is ok the zip file comes as I want it to be. and this is part of the code: --------------------------- require ("incl/pclzip.lib.php"); $newname=$name.".zip"; $zipfile = new PclZip($newname); $v_list = $zipfile->create($name); if ($v_list == 0) { die ("Error: " . $zipfile->errorInfo(true)); } header("Content-type: application/octet-stream"); header("Content-disposition: attachment; filename=$newname"); readfile($newname); //this is to delete the modified file and the zipped one after being downloaded unlink($name); unlink($newname); print "done"; ?> ------------ can you help make those zip files come with names without numbering and i saw this idea in a subtitle site and it works fine. Quote Link to comment https://forums.phpfreaks.com/topic/167393-zip-file-naming-problem/ Share on other sites More sharing options...
.josh Posted July 25, 2009 Share Posted July 25, 2009 It sounds like your browser is doing that to prevent the new file you are downloading from overwriting an already existing one in the target location (downloads folder or wherever your default download location is). You can change your own browser settings but you can't code it to not do that in browsers in general. Only way to prevent it is to have it create a unique zip file name every time (like, based on timestamp or something). Quote Link to comment https://forums.phpfreaks.com/topic/167393-zip-file-naming-problem/#findComment-882663 Share on other sites More sharing options...
serious1234 Posted July 25, 2009 Author Share Posted July 25, 2009 I tried a way to solve the problem. I added something to change . to _ so as to avoid the problem but it doesn't replace the . but replaces anything else.i think this is very odd!! anyone can help ? Quote Link to comment https://forums.phpfreaks.com/topic/167393-zip-file-naming-problem/#findComment-882749 Share on other sites More sharing options...
mmarif4u Posted July 25, 2009 Share Posted July 25, 2009 Did you tried to use timestamp as suggested above instead of $name variable. Quote Link to comment https://forums.phpfreaks.com/topic/167393-zip-file-naming-problem/#findComment-882762 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.