Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 342
  • Last Modified:

use Archive::Zip - Dont store full file path?

Hi there,

I am creating dynamic zip files on the server using Archive::Zip.

Now I have 2 problems, firstly the zip file containts full directory structure of the server, as in, /home/vhosts/httpd/ etc etc

Can I have it so just the files are stored rather than the directory structure?

I am using:

$zipperFile=$uploaddir.$audiolibrary."/pv_$fileID.mp3";
    $zip->addFile( $zipperFile )
               or warn "Error adding file $fileToAdd\n";


Also, the files in the above example are named pv_$fileID.mp3, but to make more sense, I would like to rename them to a field out of the database, so is there a way of saying "add this file, but call it this..." type command?

Any help appreciated!!

0
scooter41
Asked:
scooter41
  • 2
  • 2
1 Solution
 
Kim RyanIT ConsultantCommented:
It looks like you are creating the full file path, but the variable $fileID is not getting substituted in the name correctly.

It's easy to just use the file name. If $fileID is unique (I'm guessing it should be), just use this:

$zipperFile= 'pv_' . $fileID' . '.mp3';  # $fileID is unqiue combo like 1234
$zip->addFile( $zipperFile )             # add file pb_1234.mp3 to the archive
    or warn "Error adding file $fileToAdd\n";
0
 
scooter41Author Commented:
Hey teraplane, thanks for your reply,

The actual script above works fine, there wasnt a problem with it, it does store, PV_1000054.mp3 for example, but the actual title of that file is Every_Body_Say_Yeah which would be a lot easier if I could add PV_10000054.mpe to the zip file, but rename it Every_Body_Say_Yeah.mp3 to the zip file.

That is what I am trying to do.

I guess with directories I could make it a local path and see what happens, I just thought there may be a tag that doesnt include the directories.
0
 
Kim RyanIT ConsultantCommented:
Actually that is easy to do as well, supply a second parameter to addFile, and it will use that name in the archive, rather than actual file name.

$zip->addFile( $zipperFile,"Every_Body_Say_Yeah.mp3" );
0
 
scooter41Author Commented:
hey guess what, that worked perfectly, plus by specifying the name of the file, stripped the path data out too, mission successfull!

Thanks heaps!
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now