function error( $msg ) { print("ERROR: ".$msg); exit(); } session_start(); if ( ! $_SESSION['role']=='albumAuthor' ) { error("bad role"); } function renameAlbum( $album, $newName ) { $root= "/home/jbf/imageDatabase"; rename( $root.$album, $root.$newName ); return 0; } # $localFolder directory local to the server, containing JPGs # $album name of the new album # returns 0 if successful, != 0 otherwise function importAlbumLocal( $localFolder, $album ) { $root= "/home/jbf/imageDatabase"; $localFolder= $localFolder.'/'; $myDirectory= dir( $localFolder ); $result= 0; mkdir( $root.'/'.$album ); while( $listImage= $myDirectory->read() ) { if ( strpos( $listImage, '.png', 0 )!=FALSE || strpos( $listImage, '.JPG', 0 )!=FALSE ) { if ( ! copy( $localFolder.$listImage, $root.'/'.$album."/".$listImage ) ) $result=1; } } return $result; } function importAlbumZip( $zipfile, $album ) { if ( !is_file( $zipfile ) ) { error("bad file:".$zipfile); } $tmp= "/tmp/albumServer/".$album."/"; $cmd= "/usr/bin/unzip \"".$zipfile."\" -d ".$tmp; if ( !is_dir( '/tmp/albumServer/' ) ) { mkdir( '/tmp/albumServer/' ); } exec( $cmd ); $myDirectory= dir( $tmp ); $folder= $myDirectory->read(); #'.' $folder= $myDirectory->read(); #'..' $folder= $myDirectory->read(); if ( $folder==FALSE ) { error("no files in ".$tmp); } if ( !is_dir( $tmp.$folder ) ) { $folder= $tmp; } else { $folder= $tmp.$folder ; } $result= importAlbumLocal( $folder, $album ); exec( "rm -r ".$tmp ); return $result; } if ( $_POST['action']=='zipUpload' ) { if ( $_POST['albumName']=="" ) { error( "bad album name" ); } if( isset($_FILES['upload_test']) ) { if($_FILES['upload_test']['error'] != UPLOAD_ERR_OK) { error("Unable to upload file!"); } else { $fileName= $_FILES['upload_test']['tmp_name']; $targetName= "/tmp/albumServer/".$albumName.".zip"; if ( move_uploaded_file( $fileName, $targetName ) ) { importAlbumZip( $targetName, $_POST['albumName'] ); header("Location: albumServer.php"); } else { error("unable to upload file"); } } } else { error( "expected upload"); } } else if ( $_POST['action']=='localImport' ) { importAlbumLocal( $_POST['localDir'], $_POST['albumName'] ); } ?>