PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, March 2, 2022

[FIXED] FB API PHP curl_setopt_array(): The usage of the @filename API for file uploading is deprecated

 March 02, 2022     facebook-graph-api, facebook-php-sdk     No comments   

Issue

Have a problem with FB PHP API and php 5.5 with uploading photo to server. When using method :

 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();
        }
    }

I get error : curl_setopt_array(): The usage of the @filename API for file uploading is deprecated. Please use the CURLFile class instead


Solution

You're using PHP 5.5 with the old way of uploading over CURL. Check out the differences at https://wiki.php.net/rfc/curl-file-upload

Old

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

New

curl_setopt($curl_handle, CURLOPT_POST, 1);
$args['file'] = new CurlFile('filename.png', 'image/png');
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $args);


Answered By - Machavity
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing