首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >filename():不推荐使用@filename上传文件

filename():不推荐使用@filename上传文件
EN

Stack Overflow用户
提问于 2013-08-28 07:54:59
回答 1查看 1.7K关注 0票数 1

FB和php5.5上传照片到服务器有问题。使用方法时:

代码语言:javascript
复制
 private function _upload( $type = '', $path = '', $message = '', $aid = '' ) {
        try {

            if ( !in_array( $type, array( 'photos', 'videos' ) ) ) {
                throw new \Exception( 'Error: Incorrect type ' );
            }

            if ( !self::getFB()->getUser() ) {
                throw new \Exception( 'Error: No user' );
            }

            if ( empty( $path ) ) {
                throw new \Exception( 'Error: path is empty' );
            }
            if ( !file_exists( realpath( $path ) ) ) {
                throw new \Exception( 'Error: file doesn\'t exists' );
            }


            if ( !empty( $aid ) ) {
                $url = "/" . $aid . "/" . $type;
            } else {
                $url = '/' . self::getFB()->getUser() . '/' . $type;
            }

            var_dump( array( $url, 'POST',

                    array(
                        'image'   => '@' . realpath( $path ),
                        'message' => $message,
                    )
                )
            );

            self::getFB()->setFileUploadSupport( TRUE );

            $ret_obj = self::getFB()->api( $url, 'POST', array(
                    'image'   => '@' . realpath( $path ),
                    'message' => $message,
                )
            );
            return $ret_obj[ 'id' ];
        } catch ( \Exception $e ) {
            return $e->getMessage();
        }
    }

我得到了错误: curl_setopt_array():不推荐使用@filename上传文件。请改用CURLFile类

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-10-29 19:32:51

您使用的是PHP5.5,它使用的是以前的上传方式。查看https://wiki.php.net/rfc/curl-file-upload的不同之处

年长的

代码语言:javascript
复制
curl_setopt($curl_handle, CURLOPT_POST, 1);
$args['file'] = '@filename.png';
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $args);

新的

代码语言:javascript
复制
curl_setopt($curl_handle, CURLOPT_POST, 1);
$args['file'] = new CurlFile('filename.png', 'image/png');
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $args);
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18482236

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档