Php 将带有逗号和其他特殊字符的文件上载到wordpress

Php 将带有逗号和其他特殊字符的文件上载到wordpress,php,wordpress,Php,Wordpress,我很难显示上传到Wordpress的带有特殊字符的文件。在我尝试像john,smith.jpg这样上传文件之前,我的函数工作正常。Wordpress上载所有文件,因此这不是问题。问题是从Wordpress返回的url没有被解释为浏览器的有效源文件url 例如,当我上传文件marcia,dave_03.jpg时,返回的URL是 浏览器声称该资源不存在。我应该如何进行? 贾努斯 逗号是并且应该被编码。尝试访问http://example.com/uploads/2015/03/Dove%2CMarc

我很难显示上传到Wordpress的带有特殊字符的文件。在我尝试像john,smith.jpg这样上传文件之前,我的函数工作正常。Wordpress上载所有文件,因此这不是问题。问题是从Wordpress返回的url没有被解释为浏览器的有效源文件url

例如,当我上传文件marcia,dave_03.jpg时,返回的URL是

浏览器声称该资源不存在。我应该如何进行? 贾努斯


逗号是并且应该被编码。尝试访问
http://example.com/uploads/2015/03/Dove%2CMarcia_03.jpg
然后看看这是否有效。否。没有。我得到一个404错误。
if (in_array($_FILES['profile_photo']['type'], $types)) :
        // Your file handing script here
        $upload_overrides = array( 'test_form' => false );
        $movefile = wp_handle_upload( $_FILES['profile_photo'], $upload_overrides );
        if ( $movefile ) {
            //echo "File is valid, and was successfully uploaded.\n";

                //upload attachment
                $upload_dir = wp_upload_dir();
                //it must be absolute path to work
                $file =  $upload_dir['path'] ."/".$_FILES["profile_photo"]["name"];

                $guid = $upload_dir['url'] . '/' . basename( $_FILES["profile_photo"]["name"]);
                $attachment = array(
                    'guid'           =>$guid , 
                    'post_mime_type' => $_FILES["profile_photo"]["type"] ,
                    'post_title'     => preg_replace( '/\.[^.]+$/', '', basename( $_FILES["profile_photo"]["name"]  ) ),
                    'post_content'   => '',
                    'post_status'    => 'inherit'
                );
            // Insert the attachment.
            $photo_id = wp_insert_attachment( $attachment,$file);
            $src = wp_get_attachment_image_src( $photo_id); 

            $attach_data = wp_generate_attachment_metadata( $photo_id, $file);
            wp_update_attachment_metadata( $photo_id, $attach_data );

            User:: setUserPhoto($current_user_id, $photo_id);
        } else {
            echo "Possible file upload attack!\n";
    }   
    else:
    // Error, filetype not supported
        $messages[] = "This file type is not supported";
    endif;