Moin,
passe gerade eine Gallerie für Buddypress an, die ich mir runtergeladen haben und bin mal wieder hängen geblieben.
Ich möchte die JPG-Datei nach dem Upload mit der Bild-ID versehen, momentan wird das JPG mit dem normalen Dateinamen auf dem Server gespeichert.
Hier mal der Teil der Gallerie, von dem Ich denke, das er relevant ist:
	
ich habe schon an alle möglichen Variablen versucht, String-ketten anzuhängen (am ausichtsreichsten erschien mir $_FILES['file'] umzubennen), jedoch nie mit dem Ergebnis, das die hochgeladenen Datei umbenannt wurde :/
die ganze Gallerie gibts es übrigens hier:
WordPress › BuddyPress Album+ WordPress Plugins
gruss,
Alex
					passe gerade eine Gallerie für Buddypress an, die ich mir runtergeladen haben und bin mal wieder hängen geblieben.
Ich möchte die JPG-Datei nach dem Upload mit der Bild-ID versehen, momentan wird das JPG mit dem normalen Dateinamen auf dem Server gespeichert.
Hier mal der Teil der Gallerie, von dem Ich denke, das er relevant ist:
PHP-Code:
	
	
function bp_album_action_upload() {
    global $bp;
    
    if ( $bp->current_component == $bp->album->slug && $bp->album->upload_slug == $bp->current_action && isset( $_POST['submit'] )) {
        check_admin_referer('bp-album-upload');
        $error_flag = false;
        $feedback_message = array();
        // check privacy
        if( !isset($_POST['privacy']) ){
            $error_flag = true;
            $feedback_message[] = __( 'Please select a privacy option.', 'bp-album' );
        } else {
            $priv_lvl = intval($_POST['privacy']);
                        // TODO: Refactor this, and the bp_album_max_privXX variable as an array.
                        switch ($priv_lvl) {
                            case "0": $pic_limit = $bp->album->bp_album_max_priv0_pictures; break;
                            case "1": $pic_limit = $bp->album->bp_album_max_priv1_pictures; break;
                            case "2": $pic_limit = $bp->album->bp_album_max_priv2_pictures; break;
                            case "3": $pic_limit = $bp->album->bp_album_max_priv3_pictures; break;
                            case "4": $pic_limit = $bp->album->bp_album_max_priv4_pictures; break;
                            case "5": $pic_limit = $bp->album->bp_album_max_priv5_pictures; break;
                            case "6": $pic_limit = $bp->album->bp_album_max_priv6_pictures; break;
                            case "7": $pic_limit = $bp->album->bp_album_max_priv7_pictures; break;
                            case "8": $pic_limit = $bp->album->bp_album_max_priv8_pictures; break;
                            case "9": $pic_limit = $bp->album->bp_album_max_priv9_pictures; break;
                            default: $pic_limit = null;
                        }
            if($priv_lvl == 10 )
                $pic_limit = is_site_admin() ? false : null;
            if( $pic_limit === null){ //costant don't exist
                $error_flag = true;
                $feedback_message[] =
 __( 'Privacy option is not correct.', 'bp-album' );
            }elseif( $pic_limit !== false && ( $pic_limit === 0  || $pic_limit <= bp_album_get_picture_count(array('privacy'=>$priv_lvl)) ) ){
                $error_flag = true;
                switch ($priv_lvl){
                    case 0 :
                        $feedback_message[] =
 __( 'You reached the limit for public pictures.', 'bp-album' ).' '.__( 'Please select another privacy option.', 'bp-album' );
                        break;
                    case 2 :
                        $feedback_message[] =
 __( 'You reached the limit for pictures visible to community members.', 'bp-album' ).' '.__( 'Please select another privacy option.', 'bp-album' );
                        break;
                    case 4 :
                        $feedback_message[] = 
__( 'You reached the limit for pictures visible to friends.', 'bp-album' ).' '.__( 'Please select another privacy option.', 'bp-album' );
                        break;
                    case 6 :
                        $feedback_message[] =
 __( 'You reached the limit for private pictures.', 'bp-album' ).' '.__( 'Please select another privacy option.', 'bp-album' );
                        break;
                }
            }
        }
        $uploadErrors = array(
            0 => __("There is no error, the file uploaded with success", 'buddypress'),
            1 => __("Your image was bigger than the maximum allowed file size of: ", 'buddypress') . size_format(CORE_MAX_FILE_SIZE),
            2 => __("Your image was bigger than the maximum allowed file size of: ", 'buddypress') . size_format(CORE_MAX_FILE_SIZE),
            3 => __("The uploaded file was only partially uploaded", 'buddypress'),
            4 => __("No file was uploaded", 'buddypress'),
            6 => __("Missing a temporary folder", 'buddypress')
        );
        if ( isset($_FILES['file']) ){
        
            if ( $_FILES['file']['error'] ) {
                $feedback_message[] = 
sprintf( __( 'Your upload failed, please try again. Error was: %s', 'buddypress' ), $uploadErrors[$_FILES['file']['error']] );
                $error_flag = true;
            }
            if ( $_FILES['file']['size'] > BP_AVATAR_ORIGINAL_MAX_FILESIZE ) {
                $feedback_message[] = 
sprintf( __( 'The file you uploaded is too big. Please upload a file under %s', 'buddypress'), size_format(CORE_MAX_FILE_SIZE) );
                $error_flag = true;
            }
            if ( !bp_core_check_avatar_type( $_FILES['file'] ) ) {
                $feedback_message[] =
 __( 'Please upload only JPG, GIF or PNG photos.', 'buddypress' );
                $error_flag = true;
            }
        }else{
            $feedback_message[] = 
sprintf( __( 'Your upload failed, please try again. Error was: %s', 'buddypress' ), $uploadErrors[4] );
            $error_flag = true;
        }
        if(!$error_flag){  // If everything is ok handle the upload and move to the directory
            add_filter( 'upload_dir', 'bp_album_upload_dir', 10, 0 ); //the upload handle get the upload dir from this filter
            
            $pic_org = wp_handle_upload( $_FILES['file'],array('action'=>'picture_upload') );
            if ( !empty( $pic_org['error'] ) ) {
                $feedback_message[] =
 sprintf( __('Your upload failed, please try again. Error was: %s', 'buddypress' ), $pic_org['error'] );
                $error_flag = true;
            }
        }
        if(!$error_flag){  // If everything is ok resize the picture
            $abs_path_to_files = defined( 'BLOGUPLOADDIR' ) ? str_replace('/files/','/',BLOGUPLOADDIR) : ABSPATH;
            $pic_org_path = $pic_org['file'];
            $pic_org_url = str_replace($abs_path_to_files,'/',$pic_org_path);
            $pic_org_size = getimagesize( $pic_org_path );
            $pic_org_size = ($pic_org_size[0]>$pic_org_size[1])?$pic_org_size[0]:$pic_org_size[1];
            if($pic_org_size <= $bp->album->bp_album_middle_size){
                $pic_mid_path = $pic_org_path;
                $pic_mid_url = $pic_org_url;
            } else {
                $pic_mid = wp_create_thumbnail( $pic_org_path, $bp->album->bp_album_middle_size );
                $pic_mid_path = str_replace( '//', '/', $pic_mid );
                $pic_mid_url = str_replace($abs_path_to_files,'/',$pic_mid_path);
                if (!$bp->album->bp_album_keep_original){
                    unlink($pic_org_path);
                    $pic_org_url=$pic_mid_url;
                    $pic_org_path=$pic_mid_path;
                }
            }
            if($pic_org_size <= $bp->album->bp_album_thumb_size){
                $pic_thumb_path = $pic_org_path;
                $pic_thumb_url = $pic_org_url; // TN Name!
            } else {
                $pic_thumb = image_resize( $pic_mid_path, $bp->album->bp_album_thumb_size, $bp->album->bp_album_thumb_size, true);
                $pic_thumb_path = str_replace( '//', '/', $pic_thumb );
                $pic_thumb_url = str_replace($abs_path_to_files,'/',$pic_thumb);
            }
            $owner_type = 'user';
            $owner_id = $bp->loggedin_user->id;
            $date_uploaded =  gmdate( "Y-m-d H:i:s" );
            $title = $_FILES['file']['name'];
            $description = ' ';
            $privacy = $priv_lvl;
            $id=bp_album_add_picture($owner_type,$owner_id,$title,$description,$priv_lvl,$date_uploaded,
$pic_org_url,$pic_org_path,$pic_mid_url,$pic_mid_path,$pic_thumb_url,$pic_thumb_path);
            if($id)
                $feedback_message[] = __('Picture uploaded. Now you can change picture details.', 'bp-album');
            else {
                $error_flag = true;
                $feedback_message[] = __('There were problems saving picture details.', 'bp-album');
            }
        }
        if ($error_flag){
            bp_core_add_message( implode(' ', $feedback_message ),'error');
        } else {
            bp_core_add_message( implode(' ', $feedback_message ),'success' );
            bp_core_redirect( $bp->loggedin_user->domain . $bp->
current_component . '/'.$bp->album->single_slug.'/' . $id.'/'.$bp->album->edit_slug.'/');
            die;
        }
    }
}
add_action('wp','bp_album_action_upload',3); 
die ganze Gallerie gibts es übrigens hier:
WordPress › BuddyPress Album+ WordPress Plugins
gruss,
Alex
 
          
 Moderatorin
 Moderatorin



Kommentar