• 0

Good way to list the contents of a dropbox folder in php


Question

4 answers to this question

Recommended Posts

  • 0

This is the scraper that I have so far:


<?php

// Get drobox folder html.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.dropbox.com/sh/mneh7sehw63cvk6/VcWEokE4yH' ); // Dropbox shared folder link
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 (FM Scene 4.6.1)');
curl_setopt($ch, CURLOPT_REFERER, 'https://www.dropbox.com/');
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$html =curl_exec ($ch);
// extract links with DOMDocument
$dom = new DOMDocument();
@$dom->loadHTML($html);
$links = $dom->getElementsByTagName('a');
$processed_links = array();
foreach ($links as $link)
{
if ($link->hasAttribute('class')&& $link->hasAttribute('href'))
{
foreach ($link->attributes as $a)
{
if ($a->value=='filename-link')
{
$processed_links[$link->getAttribute('href')] = $link->getAttribute('href');
}

}

}
}


echo var_dump($processed_links);




?>
[/CODE]

  • 0

Why are you scraping a webpage when Dropbox have an API?

edit; sorry, my mistake, after looking through the Dropbox API for some reason it seems like they have a call to access shared/public folders. :huh:

  • 0
  On 22/03/2013 at 18:18, ZakO said:

Why are you scraping a webpage when Dropbox have an API?

edit; sorry, my mistake, after looking through the Dropbox API for some reason it seems like they have a call to access shared/public folders. :huh:

I found it's odd that they don't allow to simply list a directory like this without OAuth.

I managed to put together something with the scraper to get all images and txt files and display them. Seems to work ok :


<?php

// Get drobox folder html.
$folder = 'https://www.dropbox.com/sh/mneh7sehw63cvk6/VcWEokE4yH'; // Dropbox shared folder link
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $folder);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 (FM Scene 4.6.1)');
curl_setopt($ch, CURLOPT_REFERER, 'https://www.dropbox.com/');
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$html =curl_exec ($ch);
// extract links with DOMDocument
$dom = new DOMDocument();
@$dom->loadHTML($html);
$links = $dom->getElementsByTagName('a');
$processed_links = array();
foreach ($links as $link)
{
if ($link->hasAttribute('class')&& $link->hasAttribute('href'))
{
foreach ($link->attributes as $a)
{
if ($a->value=='filename-link')
{
$processed_links[$link->getAttribute('href')] = $link->getAttribute('href');
}

}

}
}

$exts = $processed_links;
foreach ($exts as $ext)
{
$url = $ext;

$path = parse_url($url, PHP_URL_PATH);

$ext2 = pathinfo($path, PATHINFO_EXTENSION);

// echo "<br> <a href=https://dl.dropbox.com$path>http://dl.dropbox.com$path</a

if ($ext2 == 'jpg')
{
echo "<br> <a href=https://dl.dropbox.com$path><imghhttps://dl.dropbox.com$path></img></a
//echo $path;
}
if ($ext2 == 'txt')
{
$first = "https://dl.dropbox.com";

$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, $first.$path); // textfile
curl_setopt($ch2, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 (FM Scene 4.6.1)');
curl_setopt($ch2, CURLOPT_REFERER, 'https://www.dropbox.com/');
curl_setopt($ch2, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch2, CURLOPT_AUTOREFERER, true);
curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch2, CURLOPT_TIMEOUT, 5);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
$str =curl_exec ($ch2);
//echo preg_replace('!\r?\n!', '<br>', $str);
echo '<pre>';
echo preg_replace('!\r?\n!', '<br>', $str);
echo '</pre>';
}
}

?>
[/CODE]

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Windoze 11 delivering whatever drivers to me in a recent laptop (2024) made me disable the ability to receive drivers altoghether. I was repeatedly losing the ability to have a lighted keyboard, because I'd install the most recent driver from the manufacturer, and Windoze would immediately "replace it" or "complement it" with a whatever "Component download" of its own. Wasted me a couple of days troubleshooting that crap. Windoze 11 wasting my time since like forever.
    • Apple iOS 26 beta has a hidden iPhone ringtone by Aditya Tiwari If you're waiting for a new iPhone ringtone to attend your calls, Apple might be baking something for this year. The recently announced iOS 26 update hides a new ringtone for iPhone, discovered in the source code of its first developer beta. Details about the new iPhone ringtone called "ReflectionAlt1-EncoreRemix" were posted on the social media platform X by @8810cfw. It was later re-shared by known Apple leaker @ShrimpApplePro and confirmed by @aaronp613. Looking back a few pages in tech history, Apple's ringtone journey began with the first iPhone in 2007. The Cupertino giant included the classic Marimba ringtone as default, which became a signature for Apple fans. Since then, Apple has continued to release new ringtones and system sounds over the years. However, it exerted more control over iPhone ringtones during the initial years. In addition to the ringtones preloaded on iPhones, Apple also allows users to buy new ringtones from the iTunes Store app. Users can also create their own custom ringtones from an audio file or a song from Apple Music using the GarageBand app. Not just Apple, tech companies have long used ringtones as a way to differentiate their devices from the rest. This includes the fallen warrior, Nokia, and newer competitors like the Google Pixel, which got a new Sound Matters collection last year. The unreleased iPhone ringtone isn't directly available to users in the Settings app as part of the developer beta. It's an alternative version of the Reflection ringtone that has been present on iPhones as the default since 2017. While it's being speculated that the ringtone could be exclusive to this year's iPhone 17 series, it's unclear if Apple will include it in upcoming iOS 26 beta releases. Apple will release the iOS 26 update later this year, featuring a range of new features, including a revamped Photos app, new iPhone wallpapers, and the Vista-like Liquid Glass design. Its public beta is expected to arrive sometime during the next month.
    • This article is about the start menu not the start button
    • This is why I wasn't really annoyed with Windows 8's full screen Start. Since Vista I launch programs by quickly pressing the WIN key and typing first few letters of whatever it is I need. Honestly, my personal equivalent of the Start menu is the WIN+X menu - it truly contains some useful things I do not feel like typing into Search.
  • Recent Achievements

    • One Month Later
      KynanSEIT earned a badge
      One Month Later
    • One Month Later
      gowtham07 earned a badge
      One Month Later
    • Collaborator
      lethalman went up a rank
      Collaborator
    • Week One Done
      Wayne Robinson earned a badge
      Week One Done
    • One Month Later
      Karan Khanna earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      681
    2. 2
      ATLien_0
      274
    3. 3
      Michael Scrip
      220
    4. 4
      +FloatingFatMan
      171
    5. 5
      Steven P.
      160
  • Tell a friend

    Love Neowin? Tell a friend!