SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question how to get file name from link?

    Hi guys, how are you all ?
    I want to get a file name from a dynamic link like this
    this link has a file called
    Code:
    anime2_bcfumwjv.sis
    I want to get this file name, is their any way?
    Thanks ...

  2. #2
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,423
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Since I don't see that file name anywhere in that link text unless you can open that link and get that content from that page I would have to say no.

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No way at all that's too bad, It's the last step in my script ...

  4. #4
    SitePoint Addict
    Join Date
    Mar 2007
    Posts
    286
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Out of interest how do you manipulate the link text anyway. E.g. you build a link in one page <domain>.index.php?page.php and you want to retrieve the page.php bit so you can get it and load it.

  5. #5
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry leonglass, but what do you mean? I can't understand what you want to know.
    If you mean how am i gonna take the links then i will tell you cURL ...
    but I just want to download the file to my server and save it as its name is
    do u understand me ??

  6. #6
    SitePoint Member
    Join Date
    Sep 2006
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What about using curl to retrieve just the header for that link, follow any redirects if applicable and get the new header, and extract the file name from the final header?

    -Jason
    DopeDomains.com - 20,000 New domains a day starting at $5
    sorted by Pagrank, Hits, Length, etc.
    Find the perfect name cheap!

  7. #7
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are going to have to request that link in order to get the filename, probably using methods from this family:

    http://us3.php.net/manual/en/ref.http.php

    http_get looks like a good place to start, but I'm just guessing.

    edit: What Jason just said sounds pretty good, and there are some curl functions available.
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  8. #8
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys for your fast help
    I am very beginner in php, I think it is my first script which I am writing now

    all I want to do is to download this link to my server with its name and get the file name to save it in my database

    this is what i am using

    $file = "$link[2]";
    $newfile = "new_name";
    if (!copy($file, $newfile)) { echo "failed to copy $file...\n"; }

    where $link[2] is the link i submitted before
    and all the problem is the new_name I want it to be automatic like the one the url shows ...

    can you give me any examples guys ... Thanks in advanced

  9. #9
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    if you base64_decode the key this is what you get:

    Code:
    61/anime2_bcfumwjv.sis|1182516152|
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  10. #10
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    logic_earth Yup, Bingo!
    Thanks a lot man ...
    I will test the result and tell you ...

  11. #11
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay guys here is the final result I got ... just for beginners like me if they based by this topic
    Code:
    $link = 'http://patricia.mobile9.com/download/content_delivery.php?key=NjEvYW5pbWUyX2JjZnVtd2p2LnNpc3wxMTgyNTE2MTUyfA==';
    $parts = Explode('key=', $link);
    $link = $parts[count($parts) - 1];
    $finish = base64_decode($link);
    preg_match("/\/(.*)\|(.*)\|/", $finish, $khaled);
    
    echo $khaled[1];

  12. #12
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    How bout something like this?
    Code php:
    function getFilename($url) {
     
        $uri = parse_url($url);
        parse_str($uri['query'], $query);
     
        /* PHP5 way
            parse_str(parse_url($url, PHP_URL_QUERY), $query);
        */
     
        return (preg_match('~/([^|]+)\|~i', base64_decode($query['key']), $regs)) ? $regs[1] : null;
     
    }
     
    $link = 'http://patricia.mobile9.com/download/content_delivery.php?key=NjEvYW5pbWUyX2JjZnVtd2p2LnNpc3wxMTgyNTE2MTUyfA==';
    $filename = getFilename($link);
     
    echo $filename;
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •