Compdigitec Labs

« | Home | »

Getting the direct link of a SkyDrive file transparently using PHP

By admin | January 31, 2011

Windows Live SkyDrive is one of the best online storage/file hosting solutions available online. It provides you with 25 GBs of free storage associated with your Windows Live ID, and allows you to upload as many files as you want to it. However, Windows Live SkyDrive’s direct links are not stable for more than a day, unlike Google Docs where the direct link is stable and permanent. Here is a PHP function that can be used to obtain the direct link of a SkyDrive file using the public URL of the file.

<?php
/*
 *      (C) Copyright 2011 Compdigitec. All rights reserved.
 *      Redistribution and use in source and binary forms, with or without
 *      modification, are permitted provided that the following conditions are
 *      met:
 *
 *      * Redistributions of source code must retain the above copyright
 *        notice, this list of conditions and the following disclaimer.
 *      * Redistributions in binary form must reproduce the above
 *        copyright notice, this list of conditions and the following disclaimer
 *        in the documentation and/or other materials provided with the
 *        distribution.
 *      * Neither the name of the Compdigitec nor the names of its
 *        contributors may be used to endorse or promote products derived from
 *        this software without specific prior written permission.
 *
 *      THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *      "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *      LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 *      A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 *      OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 *      SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 *      LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 *      DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 *      THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 *      (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 *      OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/**
 * Gets the direct link of a URL with a given public Skydrive URL
 * @param string $liveurl The public SkyDrive URL
 * @return string|false The direct URL of the skydrive or false if error
 */
function get_skydrive_direct_link($liveurl) {
	$file = file_get_contents($liveurl);

	// find file loc
	$pos = strpos($file,'<a id="spPreviewLink" href="');
	if($pos === false) return false;
	$pos += strlen('<a id="spPreviewLink" href="');

	$buffer = "";
	while(substr($file,$pos,1) != '"') {
		$buffer .= substr($file,$pos,1);
		$pos++;
	}

	$buffer = html_entity_decode($buffer);

	$directlink = substr($buffer,0,strlen($buffer)-7);

	$host = parse_url($directlink,PHP_URL_HOST);
	if(strpos($host,"livefilestore.com") === false) {
		return false;
	}
	return $directlink;
}
?>

To use this function, feed it the public URL and it will return the direct link of the file:

$direct = get_skydrive_direct_link("http://cid-abcdef1234567890.office.live.com/self.aspx/FolderName/FileName.exe");
// Returns something like http://public.bay.livefilestore.com/y1pZwjyu-qfXUWjM-si2IeNs-juO0PjZE-Sk5EVvZxgeenjCxxv9vHiUy8q1RGafKnbaGSC2alqAoIbDvAYegznaZ/FileName.exe
$not_direct = get_skydrive_direct_link("http://not.skydrive.example.com/not/a/skydrive/FileName.exe");
// Returns FALSE (if it is not a SkyDrive upload)

You can use this script as part of an independent web service or as part of your existing PHP application under the BSD license. There is a link generator on this website available that you can use to try it out or use with your application without needing the script to be installed.

If you found this article helpful or interesting, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more useful and interesting articles!

Topics: PHP | 96 Comments »

96 Responses to “Getting the direct link of a SkyDrive file transparently using PHP”

  1. nj online casino free slots Says:
    July 26th, 2022 at 23:45

    online mobile casino https://onlineplayerscasino.com/

  2. borgata free online casino Says:
    July 27th, 2022 at 01:41

    real money online casino no deposit bonus codes https://ownonlinecasino.com/

  3. jackpot casino online Says:
    July 27th, 2022 at 06:16

    speaking rock casino online gambling https://all-online-casino-games.com/

  4. online casino free bonus no deposit Says:
    July 27th, 2022 at 08:12

    best casino online real money https://casino8online.com/

  5. hotspot shield free vpn Says:
    August 7th, 2022 at 09:00

    vpn software https://freevpnconnection.com/

  6. vpn for mac free Says:
    August 7th, 2022 at 09:31

    vpn for windows 10 free https://shiva-vpn.com/

  7. premium vpn service Says:
    August 7th, 2022 at 13:28

    turbo vpn download https://freehostingvpn.com/

  8. strong vpn Says:
    August 7th, 2022 at 14:59

    vpn service usa buy https://ippowervpn.net/

  9. free vpn india Says:
    August 7th, 2022 at 18:25

    vpn service comparison https://imfreevpn.net/

  10. download express vpn Says:
    August 7th, 2022 at 21:35

    free ios vpn https://free-vpn-proxy.com/

  11. best mac vpn Says:
    August 8th, 2022 at 00:53

    free vpn for ios https://rsvpnorthvalley.com/

  12. A片 Says:
    August 18th, 2022 at 22:32

    ????

    goodddd thankssss youuuu

  13. meriking Says:
    August 25th, 2022 at 07:22

    Getting the direct link of a SkyDrive file transparently using PHP at Compdigitec Labs

    https://www.mac-aachen.de/hallo-welt/

  14. el royale online casino Says:
    August 30th, 2022 at 01:58

    casino online sin deposito https://onlinecasinos4me.com/

  15. zone online casino msn games Says:
    August 30th, 2022 at 04:36

    win real money online casino for free https://online2casino.com/

  16. online casino bonus ohne einzahlung Says:
    August 30th, 2022 at 12:56

    speaking rock casino online https://casinosonlinex.com/

  17. frree gay and bi chat sites in seattle wa Says:
    September 2nd, 2022 at 16:46

    free gay chat rooms in ioq https://newgaychat.com/

  18. gay teen chat Says:
    September 3rd, 2022 at 00:10

    gay sissie chat https://gaychatcams.net/

  19. gay bi chat line Says:
    September 3rd, 2022 at 06:19

    321 gay chat https://gaychatspots.com/

  20. indian gay chat room Says:
    September 3rd, 2022 at 10:18

    free gay/bi chat https://gay-live-chat.net/

  21. free gay chat Says:
    September 3rd, 2022 at 20:47

    chat gay room https://gayphillychat.com/

  22. gay chat random Says:
    September 4th, 2022 at 01:55

    dirty gay video chat free https://gaychatnorules.com/

  23. gaydar free gay chat Says:
    September 4th, 2022 at 03:37

    boomerang gay chat https://gaymusclechatrooms.com/

  24. free gay radom web cam chat Says:
    September 4th, 2022 at 16:17

    gay chat avenue https://gayinteracialchat.com/

  25. madridbet Says:
    September 5th, 2022 at 11:06

    Getting the direct link of a SkyDrive file transparently using PHP at Compdigitec Labs

    https://www.audamedic.com/?p=280

  26. madridbet Says:
    September 6th, 2022 at 08:51

    Getting the direct link of a SkyDrive file transparently using PHP at Compdigitec Labs

    https://nulled.soovam.com/wordpress-print-posts-pages-pdf-1-5-4.html

  27. madridbet Says:
    October 6th, 2022 at 05:18

    Getting the direct link of a SkyDrive file transparently using PHP at Compdigitec Labs

    https://www.easyfie.com/tg112/portfolio

  28. random gay chat with a stranger Says:
    October 20th, 2022 at 09:59

    wed chat gay free https://gaymanchatrooms.com/

  29. will you write my paper for me Says:
    October 20th, 2022 at 11:16

    custom papers online https://term-paper-help.org/

  30. write my paper fast Says:
    October 20th, 2022 at 13:26

    help writing a paper https://uktermpaperwriters.com/

  31. pay to write paper Says:
    October 20th, 2022 at 15:15

    paper writer service https://paperwritinghq.com/

  32. paper writers for college Says:
    October 20th, 2022 at 17:00

    buy a college paper https://writepapersformoney.com/

  33. buy writing paper Says:
    October 20th, 2022 at 18:18

    websites to type papers https://write-my-paper-for-me.org/

  34. find someone to write my college paper Says:
    October 20th, 2022 at 19:26

    custom papers online https://doyourpapersonline.com/

  35. buy custom papers online Says:
    October 20th, 2022 at 21:11

    papers writing help https://top100custompapernapkins.com/

  36. pay for a paper Says:
    October 20th, 2022 at 21:42

    paper writer service https://researchpaperswriting.org/

  37. paper writing services legitimate Says:
    October 21st, 2022 at 01:08

    paper writers for college https://writingpaperservice.net/

  38. pay to write a paper Says:
    October 21st, 2022 at 02:00

    i need help writing a paper https://buyessaypaperz.com/

  39. buy custom papers Says:
    October 21st, 2022 at 03:57

    where can i find someone to write my paper https://mypaperwritinghelp.com/

  40. custom paper writers Says:
    October 21st, 2022 at 05:10

    i need help writing a paper https://writemypaperquick.com/

  41. write my nursing paper Says:
    October 21st, 2022 at 06:21

    buy a literature review paper https://essaybuypaper.com/

  42. help with writing papers Says:
    October 21st, 2022 at 07:57

    ghost writer for college papers https://papercranewritingservices.com/

  43. paper writer online Says:
    October 21st, 2022 at 08:38

    buy college paper https://premiumpapershelp.com/

  44. write my paper one day Says:
    October 21st, 2022 at 09:53

    i will pay you to write my paper https://ypaywallpapers.com/

  45. meritking Says:
    October 23rd, 2022 at 17:38

    Getting the direct link of a SkyDrive file transparently using PHP at Compdigitec Labs

    https://laziziexpeditions.com/itinerary/

  46. grandpashabet Says:
    November 5th, 2022 at 07:17

    Getting the direct link of a SkyDrive file transparently using PHP at Compdigitec Labs

    http://hydrosphere-91.net/

Comments