1

サーバーへの写真のアップロードで、FB PHP API と php 5.5 に問題があります。メソッドを使用する場合:

 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 API を使用することは非推奨です。代わりに CURLFile クラスを使用してください

4

1 に答える 1

3

CURL 経由でアップロードする古い方法で PHP 5.5 を使用しています。https://wiki.php.net/rfc/curl-file-uploadで違いを確認してください

curl_setopt($curl_handle, CURLOPT_POST, 1);
$args['file'] = '@filename.png';
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $args);

新しい

curl_setopt($curl_handle, CURLOPT_POST, 1);
$args['file'] = new CurlFile('filename.png', 'image/png');
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $args);
于 2013-10-29T19:32:51.723 に答える