Пример #1
0
 /** Returns an array of strings (for error messages) and image objects (for successful). */
 public static function createFromArchive($filename, $objAlbum)
 {
     if (!class_exists('ZipArchive')) {
         return "image_nozip";
     }
     $arrRet = array();
     $zipArchive = new ZipArchive();
     $zipArchive->open($filename);
     for ($i = 0; $i < $zipArchive->numFiles; $i++) {
         /* We stat the file, to get its name. */
         $stat = $zipArchive->statIndex($i);
         $strInName = $stat['name'];
         /* Open the temp output file. This is vulnerable to a race condition. TODO. */
         $filename = tempnam("/tmp", "OSPAP2");
         $out = fopen($filename, 'w');
         /* Get the file stream from the archive. */
         $in = $zipArchive->getStream($stat['name']);
         /* Read the file from the zip. It takes several iterations to get to the end, so we loop. */
         while (!feof($in)) {
             fputs($out, fgets($in));
         }
         /* Close the input and output files. */
         fclose($out);
         fclose($in);
         /* Determine the mimetype from the filename. None of php's built-in functions seem to work.. */
         if (preg_match("/\\.png\$/", $stat['name'])) {
             $mimetype = "image/png";
         } elseif (preg_match("/\\.gif\$/", $stat['name'])) {
             $mimetype = "image/gif";
         } elseif (preg_match("/\\.jpg\$/", $stat['name'])) {
             $mimetype = "image/jpeg";
         } elseif (preg_match("/\\.jpeg\$/", $stat['name'])) {
             $mimetype = "image/jpeg";
         } else {
             $mimetype = "unknown";
         }
         /* Create the new file. */
         $new = clsPicture::createFromFile($filename, $mimetype, $objAlbum);
         /* Delete the file. */
         unlink($filename);
         if (is_string($new)) {
             $strError = $new;
             $new = new clsDB('image');
             $new->set('error', $strError);
             $new->set('name', $stat['name']);
         } else {
             $new->set('original_name', $stat['name']);
             $new->set('original_mime', $mimetype);
             $new->set('original_size', $stat['size']);
         }
         /* Add it to the array (note that it can be a string (for an error) or an image object. */
         $arrRet[] = $new;
     }
     if (sizeof($arrRet) == 0) {
         return 'image_nofiles';
     }
     return $arrRet;
 }
Пример #2
0
             $objAlbum->set('date', date('Y-m-d H:i:s', strtotime($arrResult['date_created']) + $i++), false);
             /* Adding '$i' here is a bit of a kludge, but it keeps dates sortable (since ospap1 didn't keep track of times). */
             $objAlbum->set('user_id', $user_id);
             $objAlbum->set('mime', 'image/jpeg');
             $objAlbum->set('max_width', '640');
             $objAlbum->set('max_height', '480');
             $objAlbum->setDefaultPolicies($objOwner);
             $objAlbum->save();
             $arrAlbums[$arrResult['category_id']] = $objAlbum;
         }
         $objAlbum = $arrAlbums[$arrResult['category_id']];
         print "Importing from '" . $objAlbum->get('name') . "'<br>";
         $i = 0;
         $pictureResult = mysql_query("SELECT * FROM pictures WHERE category_id = '" . $arrResult['category_id'] . "' ");
         while ($arrPictureResult = mysql_fetch_assoc($pictureResult)) {
             $objPicture = clsPicture::createFromFile($upload_directory . '/' . $arrPictureResult['filename'], 'image/jpeg', $objAlbum);
             $objPicture->set('user_id', $user_id);
             $objPicture->set('album_id', $objAlbum->get('id'));
             $objPicture->set('title', str_replace("<br />", "", html_entity_decode($arrPictureResult['title'])));
             $objPicture->set('caption', str_replace("<br />", "", html_entity_decode($arrPictureResult['caption'])));
             $objPicture->set('date', date('Y-m-d H:i:s', strtotime($arrPictureResult['date_added']) + $i++), false);
             $objPicture->set('confirmed', 1);
             $objPicture->save();
             print "<img src='" . clsThumbnail::getUrl($objPicture, 70, 70) . "'> ";
             if (++$i % 6 == 0) {
                 print "<br>";
             }
         }
         print "<br><br>";
     }
 }
Пример #3
0
                 $objPicture->set('album_id', $objAlbum->get('id'));
                 if ($objUser) {
                     $objPicture->set('user_id', $objUser->get('id'));
                     $objPicture->set('username', $objUser->get('username'));
                 } else {
                     $objPicture->set('username', $_REQUEST['username']);
                 }
                 $objPicture->set('confirmed', 0);
                 $objPicture->save();
                 print "<span class='message'>'" . $objPicture->get('original_name') . "' was saved successfully.</span><br>";
             }
         }
         $strSubAction = 'preview';
     }
 } else {
     $objPicture = clsPicture::createFromFile($tmp_name, $type, $objAlbum);
     if (is_string($objPicture)) {
         print "<span class='error'>'" . htmlentities($name) . "' failed to upload: '<strong>" . $arrMessages[$objPicture] . "</strong>'</span><br>";
     } else {
         $objPicture->set('album_id', $objAlbum->get('id'));
         if ($objUser) {
             $objPicture->set('user_id', $objUser->get('id'));
             $objPicture->set('username', $objUser->get('username'));
         } else {
             $objPicture->set('username', $_REQUEST['username']);
         }
         $objPicture->set('original_name', $name);
         $objPicture->set('original_mime', $type);
         $objPicture->set('original_size', $size);
         $objPicture->set('confirmed', 0);
         $objPicture->save();