How get FileNane with Curl

Discussion in 'PHP' started by etusha, Mar 25, 2010.

  1. #1
    i have problem with filename
    that im looking for is
    how to get filename not give filename every time
     
    etusha, Mar 25, 2010 IP
  2. pig2cat

    pig2cat Active Member

    Messages:
    299
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Hi,
    please elaborate your question more.
    we can't help you if we don't understand what exactly you want to do (what is your input, process and output?)
     
    pig2cat, Mar 25, 2010 IP
  3. etusha

    etusha Peon

    Messages:
    203
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    function get_file($file, $newfilename)
    {
    $err_msg = '';
    echo "<br>Attempting message download for $file<br>";
    $out = fopen($newfilename, 'wb');
    if ($out == FALSE){
    print "File not opened<br>";
    exit;
    }

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_FILE, $out);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_URL, $file);

    curl_exec($ch);
    echo "<br>Error is : ".curl_error ( $ch);

    curl_close($ch);
    //fclose($handle);

    }//end function
    // this is a simple download function that download remote file
    // but every time i need to use it i should give $url and $filename .
    // that im looking for is give only the $url download and save file
    // with same name that is on remote host
    // if file is called attachment.zip save it with same name
    // get_file("http://www.remote.com/files/attachment.zip");
     
    etusha, Mar 25, 2010 IP
  4. pig2cat

    pig2cat Active Member

    Messages:
    299
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    60
    #4
    Hi, you can use the php basename function

    
    function get_file($file)
    {
    $err_msg = '';
    $newfilename = basename($file);
    /... nothing changed past here
    
    PHP:
     
    pig2cat, Mar 25, 2010 IP
  5. etusha

    etusha Peon

    Messages:
    203
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    basename and pregmatch cant help me
    if link is site.com/?down=2131

    is any other way i can get only file name maybe not using curl
     
    etusha, Mar 29, 2010 IP
  6. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #6
    What has that got to do with filename?, vague description = vague reply.

    Please reply with an example input and expected output (such as a link, and where the filename comes from that link...), so we can help you better.
     
    danx10, Mar 29, 2010 IP
  7. K.Meier

    K.Meier Well-Known Member

    Messages:
    281
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #7
    Can you please explain what you mean? No one here understands your problem. Explain in detail what you are trying to do and what your problem is.
     
    K.Meier, Mar 29, 2010 IP