Source for file upload_inc.php
Documentation is available at upload_inc.php
global $gBitUser, $gContent, $gBitSystem, $fisheyeErrors, $fisheyeWarnings, $fisheyeSuccess, $gFisheyeUploads;
// first of all set the execution time for this process to unlimited
usort( $pFiles, 'fisheye_sort_uploads' );
$pFiles[$key]['type'] = $gBitSystem->verifyMimeType( $pFiles[$key]['tmp_name'] );
if( preg_match( '/(^image|pdf|vnd)/i', $pFiles[$key]['type'] ) ) {
$upImages[$key] = $pFiles[$key];
// clone the request data so edit service values are passed into store process
$upData[$key] = $_REQUEST;
// add the form data for each upload
if( !empty( $_REQUEST['imagedata'][$i] ) ) {
array_merge( $upData[$key], $_REQUEST['imagedata'][$i] );
} elseif( !empty( $pFiles[$key]['tmp_name'] ) && !empty( $pFiles[$key]['name'] ) ) {
$upArchives[$key] = $pFiles[$key];
$gallery_additions = array();
// No gallery was specified, let's try to find one or create one.
if( empty( $_REQUEST['gallery_additions'] ) ) {
$gBitSystem->fatalError( tra( "You don't have permissions to create a new gallery. Please select an existing one to insert your images to." ));
// resize original if we the user requests it
if( !empty( $_REQUEST['resize'] ) ) {
$upImages[$key]['resize'] = $_REQUEST['resize'];
if( !is_object( $gContent ) || !$gContent->isValid() ) {
if( !empty( $gFisheyeUploads ) ){
$_REQUEST['uploaded_objects'] = &$gFisheyeUploads;
$gContent->invokeServices( "content_post_upload_function", $_REQUEST );
* fisheye_get_default_gallery_id
$getHash = array( 'user_id' => $pUserId, 'max_records' => 1, 'sort_mode' => 'created_desc', 'show_empty' => TRUE );
$upList = $gal->getList( $getHash );
if( !empty( $upList ) ) {
} else { // if( $gBitUser->hasPermission( 'p_fisheye_create' ) ) {
$galleryHash = array( 'title' => $pNewName );
if( $gal->store( $galleryHash ) ) {
$getHash = array( 'max_records' => 1, 'sort_mode' => 'created_desc' );
$upList = $gal->getList( $getHash );
if( !empty( $upList ) ) {
if( $ret && (!is_object( $gContent ) || !$gContent->isValid()) ) {
global $gBitSystem, $gFisheyeUploads;
// verifyMimeType to make sure we are working with the proper file type assumptions
$pFileHash['type'] = $gBitSystem->verifyMimeType($pFileHash['tmp_name']);
// make a copy for each image we need to store
// Store/Update the image
$pImageData['_files_override'] = array( $pFileHash );
$pImageData['purge_from_galleries'] = TRUE;
if( !$image->store( $pImageData ) ) {
// play with image some more if user has requested it
$image->rotateImage( 'auto' );
$image->addToGalleries( $_REQUEST['gallery_additions'] );
$gFisheyeUploads[] = $image;
// when we're using xupload, we need to remove temp files manually
@unlink( $pFileHash['tmp_name'] );
* Recursively builds a tree where each directory represents a gallery, and files are assumed to be images.
global $gBitSystem, $gBitUser;
if( empty( $pParentGallery ) && !is_file( $pFileHash['tmp_name'] ) ) {
$galleryHash = array( 'title' => basename( $destDir ) );
if( !$pParentGallery->store( $galleryHash ) ) {
$gContent = &$pParentGallery;
$errors['upload'] = tra( 'Your upload could not be processed because it was determined to be a non-image and you only have permission to upload images.' );
* Recursively builds a tree where each directory represents a gallery, and files are assumed to be images.
global $gBitSystem, $gBitUser;
if( $archiveDir = opendir( $pDestinationDir ) ) {
while( $fileName = readdir($archiveDir) ) {
$sortedNames[] = $fileName;
foreach( $sortedNames as $fileName ) {
if( $fileName == 'Thumbs.db' ) {
unlink( "$pDestinationDir/$fileName" );
if( !preg_match( '/^\./', $fileName ) && ( $fileName != 'Thumbs.db' ) ) {
$mimeResults = $gBitSystem->verifyFileExtension( $pDestinationDir. '/'. $fileName );
'type' => $mimeResults[1],
'size' => filesize( "$pDestinationDir/$fileName" ),
'tmp_name' => "$pDestinationDir/$fileName",
if( !empty( $_REQUEST['resize'] ) && is_numeric( $_REQUEST['resize'] ) ) {
$scanFile['max_height'] = $scanFile['max_width'] = $_REQUEST['resize'];
if( is_dir( $pDestinationDir. '/'. $fileName ) ) {
if( $fileName == '__MACOSX' ) {
unlink_r( $pDestinationDir. '/'. $fileName );
// We found a new Gallery!
$galleryHash = array( 'title' => str_replace( '_', ' ', $fileName ) );
if( $newGallery->store( $galleryHash ) ) {
$newGallery->addToGalleries( $_REQUEST['gallery_additions'] );
$pParentGallery->addItem( $newGallery->mContentId, $order );
} elseif( preg_match( '/.+\/*zip*/', $scanFile['type'] ) ) {
$imageHash = array( '_files_override' => array( $scanFile ) );
if( $newImage->store( $imageHash ) ) {
$newImage->addToGalleries( $_REQUEST['gallery_additions'] );
$pParentGallery->addItem( $newImage->mContentId );
} elseif( is_file( $scanFile['tmp_name'] ) ) {
// unknown file type, let's be tidy and clean it up
unlink( $scanFile['tmp_name'] );
// this function will process a directory and all it's sub directories without
// making any assumptions. hierarchy of sub directories is maintained and
// archives can be processed or simply added to the galleries.
global $gBitSystem, $gBitUser;
if( empty( $_REQUEST['gallery_additions'] ) ) {
$_REQUEST['gallery_additions'] = array();
if( $archiveDir = opendir( $pProcessDir ) ) {
while( $fileName = readdir($archiveDir) ) {
$sortedNames[] = $fileName;
foreach( $sortedNames as $fileName ) {
if( !preg_match( '/^\./', $fileName ) && ( $fileName != 'Thumbs.db' ) ) {
'type' => $gBitSystem->lookupMimeType( substr( $fileName, ( strrpos( $fileName, '.' ) + 1 ) ) ),
'size' => filesize( "$pProcessDir/$fileName" ),
'tmp_name' => "$pProcessDir/$fileName",
if( is_dir( $pProcessDir. '/'. $fileName ) ) {
// create a new gallery from directory
$galleryHash = array( 'title' => str_replace( '_', ' ', $fileName ) );
if( $dirGallery->store( $galleryHash ) ) {
$dirGallery->addToGalleries( $_REQUEST['gallery_additions'] );
if( preg_match( '/(^image|pdf)/i', $scanFile['type'] ) ) {
$imageHash = array( 'upload' => $scanFile );
if( $newImage->store( $imageHash ) ) {
$newImage->addToGalleries( $_REQUEST['gallery_additions'] );
// if we have a gallery to add these images to, load one of them
if( !empty( $_REQUEST['gallery_additions'][0] ) && @!is_object( $imageGallery ) ) {
$imageGallery->mGalleryId = $_REQUEST['gallery_additions'][0];
$galleryHash = array( 'title' => $gBitUser->getDisplayName(). "'s Gallery" );
if( $imageGallery->store( $galleryHash ) ) {
$imageGallery->addItem( $newImage->mContentId );
// create a new gallery from archive
if( !$archiveGallery->store( $galleryHash ) ) {
unset ( $archiveGallery );
|