How do I adjust this unzip script to place contenets in specific folder?

Posted on 2010-11-30
Last Modified: 2013-12-12
I have a simple script that works great on my server that unzips a file.  When the file is unzipped, it creates a new "folder" that is the same as the file name "CTG_product_photos".  I need the conents of the file to unzip in the "images" folder.  How do I fix this script to accomodate that?

<?php system('unzip'); ?>


<?php system('unzip'); ?>

Open in new window

Question by:rlb1
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 54

Expert Comment

by:Huseyin KAHRAMAN
ID: 34241447
-d images

<?php system('unzip -d images'); ?>

Author Comment

ID: 34241506
Thanks for your help!  That worked.  However, it is still creating a new directory, CTG_product_photos, within the images directory.  Is there a way to eliminate the creation of the new directory and just dump the images in the 'image' directory?

LVL 54

Expert Comment

by:Huseyin KAHRAMAN
ID: 34242037
maybe this

<?php system('unzip images -d images'); ?>

is there any sample that you can post here (a test zip file containing a few images)
Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.


Author Comment

ID: 34242171
OK, I used the code <?php system('unzip images -d images'); ?>
and the system returned "Archive:"

The path to the image folder is: /

I need the file to dump directly into the 'image' folder without creating a secondary folder.  

Please note: I changed 'images' to 'image' before running script.

I appreciate your help!!
LVL 54

Expert Comment

by:Huseyin KAHRAMAN
ID: 34242431
we need to know the inner structure of zip file... post a sample zip file, or open it with winzip (or some other tool and post screenshot of structure of zip file)

or lets try something else:

<?php system('unzip -x images -d images'); ?>
<?php system('mv CTG_product_photos\images images'); ?>

LVL 54

Accepted Solution

Huseyin KAHRAMAN earned 500 total points
ID: 34242511
ignore previous code

<?php system('unzip'); ?>
<?php system('mv CTG_product_photos\images images'); ?>

Author Closing Comment

ID: 34242666
Thank you for your help!!

Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question