首页 文章

PHP卷曲文件上传多部分边界

提问于
浏览
1

编写代理文件上载的应用程序 . 我正在使用CURL发布文件,但有一些问题 . 发布到脚本是可以的,它从脚本发布到下一个服务器是问题 . 我不断从服务器收到此错误:

“请求被拒绝,因为没有找到多部分边界”

这是我的代码:

$post = $_POST;

            // allow for file upload proxying
            if( !empty( $_FILES ) ){
                    // add to post data
                    foreach( $_FILES as $name => $upload ){
                            $post[ $name ] = '@' . $upload[ 'tmp_name' ] . ';type=image/png';
                    }   
            } 

            // init curl
            $ch = curl_init( $url );

            // configure options
            curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
            curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );

            // post data
            if( !empty( $post ) ){
                    curl_setopt( $ch, CURLOPT_POST, true );
                    curl_setopt( $ch, CURLOPT_POSTFIELDS, $post );
                    // for file uploads, multi-part
                    curl_setopt( $ch, CURLOPT_HTTPHEADER, array(
                            'Content-type: multipart/form-data;'
                    ) );
            }   

            // execute and get return value 
            $return = trim( curl_exec( $ch ) );

            // cleanup
            curl_close( $ch );
            unset( $ch );

我在网上看到的一切都表明这应该有用,而且设置 Headers 内容类型是不必要的,但当我删除内容类型时,我收到此错误:

“请求不包含multipart / form-data或multipart / mixed流,内容类型标头为null”

有任何想法吗?提前致谢

1 回答

  • 0

    不确定问题究竟是什么,但是当我发布这个问题时我在本地工作 . 将代码移动到实时服务器上,问题就消失了......

相关问题