Author Topic: Automatic zip extraction  (Read 13343 times)

0 Members and 1 Guest are viewing this topic.

Offline bhafer

  • Newbie
  • *
  • Posts: 36
    • View Profile
    • Hafer Technology Solutions
Automatic zip extraction
« on: February 06, 2003, 05:37:02 AM »
I've seen a bunch of other gallery softwares that will automatically extract zip files with all the images in them into the database.  I know this is not a feature with this software, which is the best around.  My question is if anyone knows how to make this happen.  I would really love to have this feature, and I simply can't wait until 4homepages adds it to a later feature.  Any help would be greatly appreciated!

Regards,
Ben

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Automatic zip extraction
« Reply #1 on: February 06, 2003, 05:44:42 AM »
can u tell us witch gallery has that feature?
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline bhafer

  • Newbie
  • *
  • Posts: 36
    • View Profile
    • Hafer Technology Solutions
Automatic zip extraction
« Reply #2 on: February 06, 2003, 05:47:11 AM »

Offline bernd

  • Full Member
  • ***
  • Posts: 214
    • View Profile
Automatic zip extraction
« Reply #3 on: February 06, 2003, 10:52:27 PM »
Gallery does it as well - http://gallery.sourceforge.net/

cheers,
Bernd

Offline Maweryk

  • Sr. Member
  • ****
  • Posts: 253
    • View Profile
Automatic zip extraction
« Reply #4 on: February 07, 2003, 01:00:54 AM »
Great Idea!
Look at my thread:
http://www.4homepages.de/forum/viewtopic.php?t=3946

PLEASE, can somebody write a MOD?

Thanks a lot!

Markus

Offline SLL

  • Hero Member
  • *****
  • Posts: 585
    • View Profile
Automatic zip extraction
« Reply #5 on: February 07, 2003, 09:27:28 PM »
I believe, it doesn't make much sense to zip one image only - jpeg images are already good packed. So, this should be implemented together with multiple images upload only.

Offline bhafer

  • Newbie
  • *
  • Posts: 36
    • View Profile
    • Hafer Technology Solutions
Automatic zip extraction
« Reply #6 on: February 07, 2003, 09:35:06 PM »
I agree.  This could be used for one images (doubtful) or for multiple images.  Currently other gallery softwares allow for registered users to upload all their images from one zip file, and it will publish the lot.  This way they don't have to upload one at a time.

I understand part of the problem because the software allows for a title, key words, description, etc.  But I would think you could use one for the entire upload, and then the user could go back to modify their entries per image if they choose.

I'd have to imagine this would be easily accomplished from someone who understands php well, which I don't . . . not at that level.  I have talked to programmers who have implemented this type of solution, and they seemed to think it was pretty straight forward.  There only grey area was on the software itself, and actually implementing the solution to work.

Has anyone created a Mod to allow for this kind of feature?  Additionally, is there anything in a near future release that would have this available?

Thanks again,
Ben

Offline Maweryk

  • Sr. Member
  • ****
  • Posts: 253
    • View Profile
Automatic zip extraction
« Reply #7 on: February 07, 2003, 09:52:19 PM »
Part of the Code from  http://gallery.sourceforge.net

add_photos.php:

Code: [Select]
<span class="popuphead">Add Photos</span>
<br>
<span class="popup">
Click the <b>Browse</b> button to locate a photo to upload.
<span class="admin">
<?php if &#40;$gallery->app->feature["zip"&#93;&#41; &#123; ?>
<br>
&nbsp;&nbsp;Tip:  Upload a ZIP file full of photos and movies!
<?php &#125; ?>
<br>
&nbsp;&nbsp;(Supported file types: <?php echo join&#40;", ", acceptableFormatList&#40;&#41;&#41; ?>)
</span>

<br><br>
<?php echo makeFormIntro&#40;"add_photos.php",
array&#40;"name" => "count_form",
"method" => "POST"&#41;&#41;; ?>

1. Select the number of files you want to upload:
<select name="boxes" onChange='reloadPage()'>
<?php for &#40;$i = 1; $i <= 10;  $i++&#41; &#123;
echo "<option ";
        if &
#40;$i == $boxes&#41; &#123;
echo "selected ";
&#125;
echo "value=\"$i\">$i\n";

&
#125; ?>

</select>
<br>
</form>

<?php echo makeFormIntro&#40;"save_photos.php",
array&#40;"name" => "upload_form",
"enctype" => "multipart/form-data",
"method" => "POST"&#41;&#41;; ?>

2. Use the Browse button to find the photos on your computer
<input type="hidden" name="max_file_size" value="10000000">
<table>
<?php for &#40;$i = 0; $i < $boxes;  $i++&#41; &#123; ?>
<tr><td>
File</td>
<td><input name="userfile[]" type="file" size=40></td></tr>
<td>Caption</td><td> <input name="usercaption[]" type="text" size=40></td></tr>
<tr><td></td></tr>
<?php &#125; ?>
</table>
<input type=checkbox name=setCaption checked value="1">Use filename as caption if no caption is specified.
<br>
<center>
<input type="button" value="Upload Now" onClick='opener.showProgress(); document.upload_form.submit()'>
<input type=submit value="Cancel" onclick='parent.close()'>
</center>
</form>

<?php echo makeFormIntro&#40;"save_photos.php",
array&#40;"name" => "uploadurl_form",
"method" => "POST"&#41;&#41;; ?>

Or, upload any images found at this location.  The location
can either be a URL or a directory on the server.
<br>
<span class="admin">
&nbsp;&nbsp;Tip: FTP images to a directory on your server then provide that path here!
</span>
<br>

<input type="text" name="urls[]" size=40>
<br>
<input type=checkbox name=setCaption checked value="1">Set photo captions with original filenames.
<br>
<center>
<input type="button" value="Submit URL or directory" onClick='opener.showProgress(); document.uploadurl_form.submit()'>
<input type=submit value="Cancel" onclick='parent.close()'>
</center>
</form>


save_photos.php:

Code: [Select]
<?php
// Hack prevention.
if &#40;!empty&#40;$HTTP_GET_VARS["GALLERY_BASEDIR"&#93;&#41; ||
!empty&#40;$HTTP_POST_VARS["GALLERY_BASEDIR"&#93;&#41; ||
!empty&#40;$HTTP_COOKIE_VARS["GALLERY_BASEDIR"&#93;&#41;&#41; &#123;
print "Security violation\n";
exit;
&
#125;
?>

<?php require&#40;$GALLERY_BASEDIR . "init.php"&#41;; ?>
<?php
// Hack check
if &#40;!$gallery->user->canAddToAlbum&#40;$gallery->album&#41;&#41; &#123;
exit;
&
#125;

if &#40;$userfile_name&#41; &#123;
$file_count 0;
foreach &#40;$userfile_name as $file&#41; &#123;
if &#40;$file&#41; &#123;
$file_count++;
&#125;
&#125;
&#125;

function msg&#40;$buf&#41; &#123;
global $msgcount;

if &#40;$msgcount&#41; &#123;
print "<br>";
&#125;
print $buf;
my_flush&#40;&#41;;
$msgcount++;
&
#125;

?>

<html>
<head>
  <title>Processing and Saving Photos</title>
  <?php echo getStyleSheetLink&#40;&#41; ?>

</head>
<body onLoad='opener.hideProgressAndReload();'>

<?php
if &#40;$urls&#41; &#123;
?>

<span class=title>Fetching Urls...</span>
<br>
<?php
/* Process all urls first */
$temp_files = array&#40;&#41;;

foreach &#40;$urls as $url&#41; &#123;

        /* Get rid of any extra white space */
        $url trim&#40;$url&#41;;

/*
 * Check to see if the URL is a local directory &#40;inspired by
 * code from Jared &#40;hogalot&#41;
 */
if &#40;fs_is_dir&#40;$url&#41;&#41; &#123;
msg&#40;"Processing <i>$url</i> as a local directory."&#41;;
$handle fs_opendir&#40;$url&#41;;
while &#40;&#40;$file = readdir&#40;$handle&#41;&#41; != false&#41; &#123;
if &#40;$file != "." && $file != ".."&#41; &#123;
$tag ereg_replace&#40;".*\.&#40;[^\.&#93;*&#41;$", "\\1", $file&#41;;
$tag strtolower&#40;$tag&#41;;
if &#40;acceptableFormat&#40;$tag&#41;&#41; &#123;
/* Tack it onto userfile */
if &#40;substr&#40;$url,-1&#41; == "/"&#41; &#123;
$image_tags[&#93; = fs_export_filename&#40;$url . $file&#41;;
&#125; else &#123;
$image_tags[&#93; = fs_export_filename&#40;$url . "/" . $file&#41;;
&#125;
&#125;
&#125;
&#125;
closedir&#40;$handle&#41;;
continue;
&#125;

/* Get rid of any preceding whitespace &#40;fix for odd browsers like konqueror&#41; */
$url eregi_replace&#40;"^[[&#58;space&#58;&#93;&#93;+", "", $url&#41;;

/* If the URI doesn't start with a scheme, prepend 'http&#58;//' */
if &#40;!fs_is_file&#40;$url&#41;&#41; &#123;
if &#40;!ereg&#40;"^&#40;http|ftp&#41;", $url&#41;&#41; &#123;
$url "http&#58;//$url";
&#125;
&#125;

/* Parse URL for name and file type */
$url_stuff parse_url&#40;$url&#41;;
$name basename&#40;$url_stuff["path"&#93;&#41;;
$tag ereg_replace&#40;".*\.&#40;[^\.&#93;*&#41;$", "\\1", $url&#41;;
$tag strtolower&#40;$tag&#41;;

/* Dont output warning messages if we cant open url */

/*
 * Try to open the url in lots of creative ways.
 * Do NOT use fs_fopen here because that will pre-process
 * the URL in win32 style &#40;ie, convert / to \, etc&#41;.
 */
 
$id = @fopen&#40;$url, "rb"&#41;;
if &#40;!ereg&#40;"http", $url&#41;&#41; &#123;
if &#40;!$id&#41; $id = @fopen&#40;"http&#58;//$url", "rb"&#41;;
if &#40;!$id&#41; $id = @fopen&#40;"http&#58;//$url/", "rb"&#41;;
&#125;
if &#40;!$id&#41; $id = @fopen&#40;"$url/", "rb"&#41;;

if &#40;$id&#41; &#123;
msg&#40;urldecode&#40;$url&#41;&#41;;
&#125; else &#123;
msg&#40;"Could not open url&#58; '$url'"&#41;;
continue;
&#125; 

/* copy file locally */
$file $gallery->app->tmpDir "/photo.$name";
$od fs_fopen&#40;$file, "wb"&#41;;
if &#40;$id && $od&#41; &#123;
while &#40;!feof&#40;$id&#41;&#41; &#123;
fwrite&#40;$od, fread&#40;$id, 65536&#41;&#41;;
set_time_limit&#40;$gallery->app->timeLimit&#41;;
&#125;
fclose&#40;$id&#41;;
fclose&#40;$od&#41;;
&#125;

/* Make sure we delete this file when we're through... */
$temp_files[$file&#93;++;

/* If this is an image or movie - add it to the processor array */
if &#40;acceptableFormat&#40;$tag&#41; || !strcmp&#40;$tag, "zip"&#41;&#41; &#123;
/* Tack it onto userfile */
$userfile_name[&#93; = $name;
$userfile[&#93; = $file;
&#125; else &#123;
/* Slurp the file */
msg&#40;"Parsing $url for images..."&#41;;
$fd fs_fopen &#40;$file, "r"&#41;;
$contents fread &#40;$fd, fs_filesize &#40;$file&#41;&#41;;
fclose &#40;$fd&#41;;

/* We'll need to add some stuff to relative links */
$base_url $url_stuff["scheme"&#93; . '&#58;//' . $url_stuff["host"&#93;;
$base_dir '';
if &#40;$url_stuff["port"&#93;&#41; &#123;
  $base_url .= '&#58;' $url_stuff["port"&#93;;
&#125;

/* Hack to account for broken dirname */
if &#40;ereg&#40;"/$", $url_stuff["path"&#93;&#41;&#41; &#123;
$base_dir $url_stuff["path"&#93;;
&#125; else &#123;
$base_dir dirname&#40;$url_stuff["path"&#93;&#41;;
&#125;

/* Make sure base_dir ends in a / &#40; accounts for empty base_dir &#41; */
if &#40;!ereg&#40;"/$", $base_dir&#41;&#41; &#123;
$base_dir .= '/';
&#125;

$things = array&#40;&#41;;
while &#40;$cnt = eregi&#40;'&#40;src|href&#41;="?&#40;[^" >&#93;+\.' . acceptableFormatRegexp&#40;&#41; . '&#41;[" >&#93;',
    $contents
    $results&#41;&#41; &#123;
set_time_limit&#40;$gallery->app->timeLimit&#41;;
$things[$results[2&#93;&#93;++;
$contents str_replace&#40;$results[2&#93;, "", $contents&#41;;
&#125;

/* Add each unique link to an array we scan later */
foreach &#40;array_keys&#40;$things&#41; as $thing&#41; &#123;

/* 
 * Some sites &#40;slashdot&#41; have images that start with // and this
 * confuses Gallery.  Prepend 'http&#58;'
 */
if &#40;!strcmp&#40;substr&#40;$thing, 0, 2&#41;, "//"&#41;&#41; &#123;
$thing "http&#58;$thing";
&#125;

/* Absolute Link &#40; http&#58;//www.foo.com/bar &#41; */
if &#40;substr&#40;$thing, 0, 4&#41; == 'http'&#41; &#123;
$image_tags[&#93; = $thing;

/* Relative link to the host &#40; /foo.bar &#41;*/
&#125; elseif &#40;substr&#40;$thing, 0, 1&#41; == '/'&#41; &#123;
$image_tags[&#93; = $base_url . $thing;

/* Relative link to the dir &#40; foo.bar &#41; */
&#125; else &#123;
$image_tags[&#93; = $base_url . $base_dir . $thing;
&#125;
&#125;

/* Tell user how many links we found, but delay processing */
msg&#40;"Found " . count&#40;$image_tags&#41; . " Images."&#41;;
&#125;
&#125;
&#125; /* if &#40;$urls&#41; */
?>



<br>
<span class=title>Processing status...</span>
<br>

<?php
while &#40;sizeof&#40;$userfile&#41;&#41; &#123;
$name array_shift&#40;$userfile_name&#41;;
$file array_shift&#40;$userfile&#41;;
if &#40;!empty&#40;$usercaption&#41; && is_array&#40;$usercaption&#41;&#41; &#123;
    $caption removeTags&#40;array_shift&#40;$usercaption&#41;&#41;;
&#125;

$tag ereg_replace&#40;".*\.&#40;[^\.&#93;*&#41;$", "\\1", $name&#41;;
$tag strtolower&#40;$tag&#41;;

if &#40;$name&#41; &#123;
process&#40;$file, $tag, $name, $caption, $setCaption&#41;;
&#125;
&#125;


function process&#40;$file, $tag, $name, $caption, $setCaption=""&#41; &#123;
global $gallery;
global $temp_files;

if &#40;!strcmp&#40;$tag, "zip"&#41;&#41; &#123;
if &#40;!$gallery->app->feature["zip"&#93;&#41; &#123;
msg&#40;"Skipping $name &#40;ZIP support not enabled&#41;"&#41;;
continue;
&#125;
/* Figure out what files we can handle */
list&#40;$files, $status&#41; = exec_internal&#40;
fs_import_filename&#40;$gallery->app->zipinfo, 1&#41; . 
" -1 " .
fs_import_filename&#40;$file, 1&#41;&#41;;
sort&#40;$files&#41;;
foreach &#40;$files as $pic_path&#41; &#123;
$pic basename&#40;$pic_path&#41;;
$tag ereg_replace&#40;".*\.&#40;[^\.&#93;*&#41;$", "\\1", $pic&#41;;
$tag strtolower&#40;$tag&#41;;

if &#40;acceptableFormat&#40;$tag&#41; || !strcmp&#40;$tag, "zip"&#41;&#41; &#123;
$cmd_pic_path str_replace&#40;"[", "\[", $pic_path&#41;; 
$cmd_pic_path str_replace&#40;"&#93;", "\&#93;", $cmd_pic_path&#41;; 
exec_wrapper&#40;fs_import_filename&#40;$gallery->app->unzip, 1&#41; . 
     " -j -o " .
     fs_import_filename&#40;$file, 1&#41; .
     " \"" .
     fs_import_filename&#40;$cmd_pic_path, 1&#41; .
     "\" -d " .
     fs_import_filename&#40;$gallery->app->tmpDir, 1&#41;&#41;;
process&#40;$gallery->app->tmpDir . "/$pic", $tag, $pic, $caption, $setCaption&#41;;
fs_unlink&#40;$gallery->app->tmpDir . "/$pic"&#41;;
&#125;
&#125;
&#125; else &#123;
// remove %20 and the like from name
$name urldecode&#40;$name&#41;;
// parse out original filename without extension
$originalFilename eregi_replace&#40;".$tag$", "", $name&#41;;
// replace multiple non-word characters with a single "_"
$mangledFilename ereg_replace&#40;"[^[&#58;alnum&#58;&#93;&#93;", "_", $originalFilename&#41;;

/* Get rid of extra underscores */
$mangledFilename ereg_replace&#40;"_+", "_", $mangledFilename&#41;;
$mangledFilename ereg_replace&#40;"&#40;^_|_$&#41;", "", $mangledFilename&#41;;

/* 
need to prevent users from using original filenames that are purely numeric.
Purely numeric filenames mess up the rewriterules that we use for mod_rewrite
specifically&#58;
RewriteRule ^&#40;[^\.\?/&#93;+&#41;/&#40;[0-9&#93;+&#41;$ /~jpk/gallery/view_photo.php?set_albumName=$1&index=$2 [QSA&#93;
*/

if &#40;ereg&#40;"^&#40;[0-9&#93;+&#41;$", $mangledFilename&#41;&#41; &#123;
$mangledFilename .= "_G";
&#125;

set_time_limit&#40;$gallery->app->timeLimit&#41;;
if &#40;acceptableFormat&#40;$tag&#41;&#41; &#123;

        /*
 * Move the uploaded image to our temporary directory
 * using move_uploaded_file so that we work around
 * issues with the open_basedir restriction.
 */
if &#40;function_exists&#40;'move_uploaded_file'&#41;&#41; &#123;
        $newFile tempnam&#40;$gallery->app->tmpDir, "gallery"&#41;;
if &#40;move_uploaded_file&#40;$file, $newFile&#41;&#41; &#123;
    $file $newFile;
&#125;

/* Make sure we remove this file when we're done */
$temp_files[$newFile&#93;++;
&#125;
    
msg&#40;"- Adding $name"&#41;;
if &#40;$setCaption and $caption == ""&#41; &#123;
$caption $originalFilename;
&#125;

$err $gallery->album->addPhoto&#40;$file, $tag, $mangledFilename, $caption&#41;;
if &#40;!$err&#41; &#123;
/* resize the photo if needed */
if &#40;$gallery->album->fields["resize_size"&#93; > 0 && isImage&#40;$tag&#41;&#41; &#123;
$index $gallery->album->numPhotos&#40;1&#41;;
$photo $gallery->album->getPhoto&#40;$index&#41;;
list&#40;$w, $h&#41; = $photo->image->getRawDimensions&#40;&#41;;
if &#40;$w > $gallery->album->fields["resize_size"&#93; ||
    $h $gallery->album->fields["resize_size"&#93;&#41; &#123;
msg&#40;"- Resizing $name"&#41;; 
$gallery->album->resizePhoto&#40;$index, $gallery->album->fields["resize_size"&#93;&#41;;
&#125;
&#125;
&#125; else &#123;
msg&#40;"<font color=red>Error&#58; $err!</font>"&#41;;
msg&#40;"<b>Need help?  Look in the " .
    "<a href=http&#58;//gallery.sourceforge.net/faq.php target=_new>Gallery FAQ</a></b>"&#41;;
&#125;
&#125; else &#123;
msg&#40;"Skipping $name &#40;can't handle '$tag' format&#41;"&#41;;
&#125;
&#125;
&#125;

$gallery->album->save&#40;&#41;;

if &#40;$temp_files&#41; &#123;
/* Clean up the temporary url file */
foreach &#40;$temp_files as $tf => $junk&#41; &#123;
fs_unlink&#40;$tf&#41;;
&#125;
&#125;
?>


<?php
if &#40;!$msgcount&#41; &#123;
print "No images uploaded!";
&
#125;
?>

<center>
<form>
<input type=submit value="Dismiss" onclick='parent.close()'>
</form>
<?php
/* Prompt for additional files if we found links in the HTML slurpage */
if &#40;count&#40;$image_tags&#41;&#41; &#123;
?>


<?php $uploadUrlFormName "uploadurl_form"?>

<?php /* Note&#58; the w3c-suggested "text/javascript" doesn't work with Navigator 4 */ ?>
<script language="javascript">
// <!--
function setCheck(val) {
ufne=document.<?php echo $uploadUrlFormName?>;
len = ufne.elements.length;
for(i = 0 ; i < len ; i++) {
if (ufne.elements[i].name=='urls[]') {
ufne.elements[i].checked=val;
}
}
}
function invertCheck() {
ufne=document.<?php echo $uploadUrlFormName?>;
len = ufne.elements.length;
for(i = 0 ; i < len ; i++) {
if (ufne.elements[i].name=='urls[]') {
ufne.elements[i].checked = !(ufne.elements[i].checked);
}
}
}
// -->
</script>

<p><span class="fineprint">
<a href="javascript:setCheck(1)">Check&nbsp;All</a>
-
<a href="javascript:setCheck(0)">Clear&nbsp;All</a>
-
<a href="javascript:invertCheck()">Invert Selection</a>
</span></p>

<table><tr><td>
<?php echo makeFormIntro&#40;"save_photos.php", 
array&#40;"name" => $uploadUrlFormName, 
"method" => "POST"&#41;&#41;; ?>

<?php
/* Allow user to select which files to grab - only show url right now &#40; no image previews &#41; */
sort&#40;$image_tags&#41;;
foreach &#40; $image_tags as $image_src&#41; &#123;
print "<input type=checkbox name=\"urls[&#93;\" value=\"$image_src\" checked>$image_src<br />\n";
&#125;
?>

</td></tr></table>

<?php /* REVISIT - it'd be nice to have these functions get shoved
  into util.php at some time - maybe added functionality to the makeFormIntro? */ 
?>


<p><span class="fineprint">
<a href="javascript:setCheck(1)">Check&nbsp;All</a>
-
<a href="javascript:setCheck(0)">Clear&nbsp;All</a>
-
<a href="javascript:invertCheck()">Invert Selection</a>
</span></p>

<p>
<input type=hidden name="setCaption" value="<?php echo $setCaption?>">
<input type=button value="Add Files" onClick="opener.showProgress(); document.uploadurl_form.submit()">
</p>

</form>
</center>
<?php


Can somebody create a mod to use this feature in 4images???

Thanks,

Markus