src/Vimeo/Vimeo.php
public function uploadImage($pictures_uri, $file_path, $activate = false)
    {
        // Validate that our file is real.
        if (!is_file($file_path)) {
            throw new VimeoUploadException('Unable to locate file to upload.');
        }

        $pictures_response = $this->request($pictures_uri, array(), 'POST');
        if ($pictures_response['status'] !== 201) {
            throw new VimeoUploadException('Unable to request an upload url from vimeo');
        }

        $upload_url = $pictures_response['body']['link'];

        $image_resource = fopen($file_path, 'r');

        $curl_opts = array(
            CURLOPT_TIMEOUT => 240,
            CURLOPT_UPLOAD => true,
            CURLOPT_CUSTOMREQUEST => 'PUT',
            CURLOPT_READDATA => $image_resource
        );

        $curl = curl_init($upload_url);

        // Merge the options
        curl_setopt_array($curl, $curl_opts + $this->CURL_DEFAULTS);
        $response = curl_exec($curl);
        $curl_info = curl_getinfo($curl);

        if (!$response || !is_string($response)) {
            $error = curl_error($curl);
            throw new VimeoUploadException($error);
        }

        curl_close($curl);

        if ($curl_info['http_code'] !== 200) {
            throw new VimeoUploadException($response);
        }

        // Activate the uploaded image
        if ($activate) {
            $completion = $this->request($pictures_response['body']['uri'], array('active' => true), 'PATCH');
        }

        return $pictures_response['body']['uri'];
    }
public function uploadImage($pictures_uri, $file_path, $activate = false)
    {
        // Validate that our file is real.
        if (!is_file($file_path)) {
            throw new VimeoUploadException('Unable to locate file to upload.');
        }

        $pictures_response = $this->request($pictures_uri, array(), 'POST');
        if ($pictures_response['status'] !== 201) {
            throw new VimeoUploadException('Unable to request an upload url from vimeo');
        }

        $upload_url = $pictures_response['body']['link'];

        $image_resource = fopen($file_path, 'r');

        $curl_opts = array(
            CURLOPT_TIMEOUT => 240,
            CURLOPT_UPLOAD => true,
            CURLOPT_CUSTOMREQUEST => 'PUT',
            CURLOPT_READDATA => $image_resource
        );

        $curl = curl_init($upload_url);

        // Merge the options
        curl_setopt_array($curl, $curl_opts + $this->CURL_DEFAULTS);
        $response = curl_exec($curl);
        $curl_info = curl_getinfo($curl);

        if (!$response || !is_string($response)) {
            $error = curl_error($curl);
            throw new VimeoUploadException($error);
        }

        curl_close($curl);

        if ($curl_info['http_code'] !== 200) {
            throw new VimeoUploadException($response);
        }

        // Activate the uploaded image
        if ($activate) {
            $completion = $this->request($pictures_response['body']['uri'], array('active' => true), 'PATCH');
        }

        return $pictures_response['body']['uri'];
    }
public function uploadImage ( $ pictures_uri , $ file_path , $ activate = false ) { // Validate that our file is real. if ( ! is_file ( $ file_path ) ) { throw new VimeoUploadException ( 'Unable to locate file to upload.' ) ; } $ pictures_response = $ this -> request ( $ pictures_uri , array ( ) , 'POST' ) ; if ( $ pictures_response [ 'status' ] !== 201 ) { throw new VimeoUploadException ( 'Unable to request an upload url from vimeo' ) ; } $ upload_url = $ pictures_response [ 'body' ] [ 'link' ] ; $ image_resource = fopen ( $ file_path , 'r' ) ; $ curl_opts = array ( CURLOPT_TIMEOUT => 240 , CURLOPT_UPLOAD => true , CURLOPT_CUSTOMREQUEST => 'PUT' , CURLOPT_READDATA => $ image_resource ) ; $ curl = curl_init ( $ upload_url ) ; // Merge the options curl_setopt_array ( $ curl , $ curl_opts + $ this -> CURL_DEFAULTS ) ; $ response = curl_exec ( $ curl ) ; $ curl_info = curl_getinfo ( $ curl ) ; if ( ! $ response || ! is_string ( $ response ) ) { $ error = curl_error ( $ curl ) ; throw new VimeoUploadException ( $ error ) ; } curl_close ( $ curl ) ; if ( $ curl_info [ 'http_code' ] !== 200 ) { throw new VimeoUploadException ( $ response ) ; } // Activate the uploaded image if ( $ activate ) { $ completion = $ this -> request ( $ pictures_response [ 'body' ] [ 'uri' ] , array ( 'active' => true ) , 'PATCH' ) ; } return $ pictures_response [ 'body' ] [ 'uri' ] ; }
Uploads an image to an individual picture response.

@link https://developer.vimeo.com/api/upload/pictures
@param string $pictures_uri The pictures endpoint for a resource that allows picture uploads (eg videos and users)
@param string $file_path The path to your image file
@param boolean $activate Activate image after upload
@return string The URI of the uploaded image.
@throws VimeoRequestException
@throws VimeoUploadException
Uploads an image to an individual picture response .