<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Is posible upload file whit  PHP and get public share  link to file? in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Is-posible-upload-file-whit-PHP-and-get-public-share-link-to/m-p/626864#M28990</link>
    <description>&lt;P&gt;Yes, it is possible. Please follow the code below:&lt;/P&gt;&lt;LI-CODE lang="php"&gt;$token = 'YOUR-TOKEN'; // oauth token
$path = 'YOUR-FILE-HERE'; // Ex. text.txt or demo.mp4

/**
 * Upload file to dropbox
 */
$fp = fopen($path, 'rb');
$size = filesize($path);

$ext = end(explode('.', $path));
$d_path = uniqid().'.'.$ext;

$cheaders = array('Authorization: Bearer '.$token,
                  'Content-Type: application/octet-stream',
                  'Dropbox-API-Arg: {"path":"/'.$d_path.'", "mode":"add"}');

$ch = curl_init('https://content.dropboxapi.com/2/files/upload');
curl_setopt($ch, CURLOPT_HTTPHEADER, $cheaders);
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, $size);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);

// echo $response;
curl_close($ch);
fclose($fp);

/**
 * Get shared link
 */
$curl = curl_init();
curl_setopt_array($curl, [
    CURLOPT_URL =&amp;gt; 'https://api.dropboxapi.com/2/sharing/create_shared_link_with_settings',
    CURLOPT_RETURNTRANSFER =&amp;gt; true,
    CURLOPT_CUSTOMREQUEST =&amp;gt; 'POST',
    CURLOPT_POSTFIELDS =&amp;gt; '{
                                "path": "/' . $d_path . '",
                                "settings": {
                                    "access": "viewer",
                                    "allow_download": true,
                                    "audience": "public",
                                    "requested_visibility": "public"
                                }                        
                            }',
    CURLOPT_HTTPHEADER =&amp;gt; [
        'Content: application/json',
        'Authorization: Bearer ' . $token,
        'Content-Type: application/json'
    ]
]);

$response = curl_exec($curl);
$data = json_decode($response, true);
echo $url = $data['url'];
curl_close($curl);&lt;/LI-CODE&gt;</description>
    <pubDate>Tue, 04 Oct 2022 03:15:22 GMT</pubDate>
    <dc:creator>Encoder IT Limited</dc:creator>
    <dc:date>2022-10-04T03:15:22Z</dc:date>
    <item>
      <title>Is posible upload file whit  PHP and get public share  link to file?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Is-posible-upload-file-whit-PHP-and-get-public-share-link-to/m-p/168882#M6216</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I &amp;nbsp;want upload &amp;nbsp;a file &amp;nbsp;whit API PHP. But i want get the public link share &amp;nbsp;to my users download &amp;nbsp;the &amp;nbsp;file from their home.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is posible?&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2019 09:34:41 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Is-posible-upload-file-whit-PHP-and-get-public-share-link-to/m-p/168882#M6216</guid>
      <dc:creator>Informatica P.</dc:creator>
      <dc:date>2019-05-29T09:34:41Z</dc:date>
    </item>
    <item>
      <title>Re: Is posible upload file whit  PHP and get public share  link to file?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Is-posible-upload-file-whit-PHP-and-get-public-share-link-to/m-p/168883#M6217</link>
      <description>&lt;P&gt;Dropbox does offer an API that enables programmatic listing, uploading, downloading, and sharing of files, so this is possible. You can find everything you need to get started with the Dropbox API, including documentation, tutorials, and SDKs &lt;A href="https://www.dropbox.com/developers" target="_blank" rel="nofollow noreferrer"&gt;here&lt;/A&gt;.&amp;nbsp;You'll need to register an app &lt;A href="https://www.dropbox.com/developers/apps/create" target="_blank" rel="nofollow noreferrer"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;App authorization is processed using OAuth. You can find more information about using OAuth in our &lt;A href="https://www.dropbox.com/developers/reference/oauthguide" target="_blank" rel="nofollow noreferrer"&gt;OAuth guide&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;We don't currently have an official PHP SDK for Dropbox API v2, so if you're using PHP, you can call the &lt;A href="https://www.dropbox.com/developers/reference/oauthguide" target="_blank" rel="nofollow noreferrer"&gt;API v2 endpoints&lt;/A&gt; directly.&lt;/P&gt;
&lt;P&gt;To upload a file, you can use the &lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#files-upload" target="_blank" rel="nofollow noreferrer"&gt;/files/upload endpoint&lt;/A&gt;. To get a shared link, you can use the &lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#sharing-create_shared_link_with_settings" target="_blank" rel="nofollow noreferrer"&gt;/sharing/create_shared_link_with_settings endpoint&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Or you can use the official PHP SDK for&amp;nbsp;Dropbox API v1:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.dropbox.com/developers-v1/core/sdks/php" rel="nofollow noreferrer"&gt;https://www.dropbox.com/developers-v1/core/sdks/php&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://www.dropbox.com/developers-v1/core/start/php" rel="nofollow noreferrer"&gt;https://www.dropbox.com/developers-v1/core/start/php&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://dropbox.github.io/dropbox-sdk-php/api-docs/v1.1.x/" rel="nofollow noreferrer"&gt;https://dropbox.github.io/dropbox-sdk-php/api-docs/v1.1.x/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;In that SDK, you can upload files using the &lt;A href="https://dropbox.github.io/dropbox-sdk-php/api-docs/v1.1.x/class-Dropbox.Client.html#_getFile" target="_blank" rel="nofollow noreferrer"&gt;getFile method&lt;/A&gt;, and share them using the &lt;A href="https://dropbox.github.io/dropbox-sdk-php/api-docs/v1.1.x/class-Dropbox.Client.html#_createShareableLink" target="_blank" rel="nofollow noreferrer"&gt;createShareableLink method&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2016 04:09:41 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Is-posible-upload-file-whit-PHP-and-get-public-share-link-to/m-p/168883#M6217</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2016-03-24T04:09:41Z</dc:date>
    </item>
    <item>
      <title>Re: Is posible upload file whit  PHP and get public share  link to file?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Is-posible-upload-file-whit-PHP-and-get-public-share-link-to/m-p/168884#M6218</link>
      <description>&lt;P&gt;This is the code I have for PHP v2 for uploading a file, using curl functions, but I'm at a loss as to how to describe what the POST data should look like.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&amp;lt;?php&lt;BR /&gt;&lt;BR /&gt;$ch = curl_init();&lt;BR /&gt;curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);&lt;BR /&gt;curl_setopt($ch, CURLOPT_POST, true);&lt;BR /&gt;&lt;BR /&gt;$token = "yourtoken";&lt;BR /&gt;$host = "https://api.dropboxapi.com/";&lt;BR /&gt;&lt;BR /&gt;//set headers&lt;BR /&gt;$headers = array('Authorization: Bearer '.$token,&lt;BR /&gt; 'Content-Type: application/octet-stream',&lt;BR /&gt; 'Dropbox-API-Arg: {"path":"/test.txt","mode":"add"}',&lt;BR /&gt;);&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;PRE&gt;$f = fopen("test.txt", "rb");&lt;/PRE&gt;
&lt;PRE&gt;curl_setopt($ch, CURLOPT_URL, $host);&lt;BR /&gt;curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);&lt;BR /&gt;&lt;BR /&gt;// What should the POST data look like? Using the file handle? That doesn't work.&lt;BR /&gt;curl_setopt($ch, CURLOPT_POSTFIELDS, $f);&lt;BR /&gt;&lt;BR /&gt;$response = curl_exec($ch);&lt;BR /&gt;&lt;BR /&gt;fclose($f);&lt;BR /&gt;&lt;BR /&gt;echo "&amp;lt;br /&amp;gt;File Upload Response: &amp;lt;br /&amp;gt;";&lt;BR /&gt;var_export($response);&lt;BR /&gt;echo "&amp;lt;br /&amp;gt;File UPload HTTP CODE: &amp;lt;br /&amp;gt;";&lt;BR /&gt;var_export(curl_getinfo($ch, CURLINFO_HTTP_CODE));&lt;BR /&gt;&lt;BR /&gt;curl_close($ch);&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Aug 2016 06:48:55 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Is-posible-upload-file-whit-PHP-and-get-public-share-link-to/m-p/168884#M6218</guid>
      <dc:creator>David D.86</dc:creator>
      <dc:date>2016-08-23T06:48:55Z</dc:date>
    </item>
    <item>
      <title>Re: Is posible upload file whit  PHP and get public share  link to file?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Is-posible-upload-file-whit-PHP-and-get-public-share-link-to/m-p/168885#M6219</link>
      <description>&lt;P&gt;Your URL is wrong... it should be &lt;A href="https://content.dropboxapi.com/2/files/upload" rel="nofollow noreferrer"&gt;https://content.dropboxapi.com/2/files/upload&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;There may be other ways, but one way to post the content of a local file would be to read it into memory first. E.g., this worked for me:&lt;/P&gt;
&lt;PRE&gt;curl_setopt($ch, CURLOPT_POSTFIELDS, fread($f, filesize("test.txt")));&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Aug 2016 09:31:57 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Is-posible-upload-file-whit-PHP-and-get-public-share-link-to/m-p/168885#M6219</guid>
      <dc:creator>Steve M.</dc:creator>
      <dc:date>2016-08-23T09:31:57Z</dc:date>
    </item>
    <item>
      <title>Re: Is posible upload file whit  PHP and get public share  link to file?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Is-posible-upload-file-whit-PHP-and-get-public-share-link-to/m-p/626864#M28990</link>
      <description>&lt;P&gt;Yes, it is possible. Please follow the code below:&lt;/P&gt;&lt;LI-CODE lang="php"&gt;$token = 'YOUR-TOKEN'; // oauth token
$path = 'YOUR-FILE-HERE'; // Ex. text.txt or demo.mp4

/**
 * Upload file to dropbox
 */
$fp = fopen($path, 'rb');
$size = filesize($path);

$ext = end(explode('.', $path));
$d_path = uniqid().'.'.$ext;

$cheaders = array('Authorization: Bearer '.$token,
                  'Content-Type: application/octet-stream',
                  'Dropbox-API-Arg: {"path":"/'.$d_path.'", "mode":"add"}');

$ch = curl_init('https://content.dropboxapi.com/2/files/upload');
curl_setopt($ch, CURLOPT_HTTPHEADER, $cheaders);
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, $size);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);

// echo $response;
curl_close($ch);
fclose($fp);

/**
 * Get shared link
 */
$curl = curl_init();
curl_setopt_array($curl, [
    CURLOPT_URL =&amp;gt; 'https://api.dropboxapi.com/2/sharing/create_shared_link_with_settings',
    CURLOPT_RETURNTRANSFER =&amp;gt; true,
    CURLOPT_CUSTOMREQUEST =&amp;gt; 'POST',
    CURLOPT_POSTFIELDS =&amp;gt; '{
                                "path": "/' . $d_path . '",
                                "settings": {
                                    "access": "viewer",
                                    "allow_download": true,
                                    "audience": "public",
                                    "requested_visibility": "public"
                                }                        
                            }',
    CURLOPT_HTTPHEADER =&amp;gt; [
        'Content: application/json',
        'Authorization: Bearer ' . $token,
        'Content-Type: application/json'
    ]
]);

$response = curl_exec($curl);
$data = json_decode($response, true);
echo $url = $data['url'];
curl_close($curl);&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 04 Oct 2022 03:15:22 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Is-posible-upload-file-whit-PHP-and-get-public-share-link-to/m-p/626864#M28990</guid>
      <dc:creator>Encoder IT Limited</dc:creator>
      <dc:date>2022-10-04T03:15:22Z</dc:date>
    </item>
  </channel>
</rss>

