使用PHP将图像上传到telegra.ph

I don't know the Python language. Can someone help me understand whether I correctly converted this to PHP? I want to upload a file to http://telegra.ph with PHP, but I don't know how to upload from PHP.

This code is an example from a Python Telegraph API wrapper library:

import requests

with open('/Users/python273/Desktop/123345.jpeg', 'rb') as f:
    print(
        requests.post(
            'http://telegra.ph/upload',
            files={'file': ('file', f, 'image/jpeg')}  # image/gif, image/jpeg, image/jpg, image/png, video/mp4
        ).json()
    )

And this is my PHP code that doesn't work. Is there something wrong?

$url = 'http://example.com/image.jpg';
$img = 'http://telegra.ph/upload/';
$ch = curl_init($url);
$fp = fopen($img, 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);

When I run this code, I see the following error:

Warning: copy(telegra.ph/upload): failed to open stream: HTTP wrapper does not support writeable connections

Your code:

$img = 'http://telegra.ph/upload/';
...
$fp = fopen($img, 'wb');

PHP fopen() documentation is here http://php.net/manual/en/function.fopen.php , check what $mode parameter means. Why are you trying to open remote file for writing, if you only need to read it?