Zip

Discussion in 'PHP' started by Sky AK47, May 16, 2009.

  1. #1
    Hello,
    I currently want to let people upload zip, rar and 7z file and extract the files (only images).
    Is this possible? and how? And is it safe?
    Thanks in advance,
    sky
     
    Sky AK47, May 16, 2009 IP
  2. xxKillswitch

    xxKillswitch Peon

    Messages:
    331
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It is definetly not safe, because you don't know what is in the zip file itself.

    You can use ...

    exec("unzip zipfile.zip");
    Code (markup):
    For rar files, see...

    http://us2.php.net/manual/en/function.rar-extract.php

    I don't know about the other compression file, I have never used it. I would recommend any way around not allowing users to do this, maybe allow multiple file upload instead.

    Even file uploads are very unsafe, and I wouldn't recommend it unless you are sure about your abilities to properly check the files and excape any damage that can be caused ( uploading virus', users manipulating images with php code inside, etc ).

    There are several nice tutorials online, but there is alot of junk too. Search for secure file upload with php and use it as a learning source, but don't stop with just one. Continue reading and see how others implement security checks in file uploads.
     
    xxKillswitch, May 16, 2009 IP
  3. Sky AK47

    Sky AK47 Member

    Messages:
    298
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    45
    #3
    Ok, thanks for your reply. I decided not to do this.
    But I actually don't want to use javascript to put more file type inputs as it wouldn't look good.
    Do you have any other ideas?
     
    Sky AK47, May 17, 2009 IP
  4. xxKillswitch

    xxKillswitch Peon

    Messages:
    331
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Well, I dunno. If it were me, I would use something like Xajax to create a simple 'Add another image', so when that button is clicked it just adds a new input via Ajax ( Xajax is alot less complicated than using other large libraries like JQuery when you don't need the extra flash that a javascript library offers ).

    The inputs would be done like you do multiple checkboxes....

    <input type="file" name="images[]" />

    Xajax allows you to use PHP for all calls to Ajax, making it much easier on you if you only know PHP and no javascript. If you want to use this method, I could help you in getting in working.

    Otherwise, I don't know of any other solution that will allow multiple file uploads starting with just one input without some sort of javascript.
     
    xxKillswitch, May 17, 2009 IP
  5. Sky AK47

    Sky AK47 Member

    Messages:
    298
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    45
    #5
    Thanks, I'll sure take a look at Xajax.
     
    Sky AK47, May 17, 2009 IP