Curl PHP File Upload

Hey, der Versuch, eine Datei mit curl zu posten, funktioniert prima. Ich habe ein Problem. Ich kann meine Datei nicht außerhalb meiner post_file () - Funktion deklarieren. Ich rufe diese Funktion in meiner Anwendung oft auf und möchte, dass sie wiederverwendbar ist.

So funktioniert das:

function call_me(){
    $file_path = "/home/myfile.mov";
    $url = "http://myurl.com";
    $this->post_file($url, $file_path);
}
function post_file($url, $file_path){
    $data['Filedata'] = "@".$file_path;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
    $response = curl_exec($ch);
    return $response;
}

Das tut es jedoch nicht:

function call_me(){
    $file_path = "/home/myfile.mov";
    $url = "http://myurl.com";
    $data['Filedata'] = "@".$file_path;
    $this->post_file($url, $data);
}
function post_file($url, $data){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
    $response = curl_exec($ch);
    return $response;
}

Irgendwelche Ideen? Prost

Antworten auf die Frage(2)

Ihre Antwort auf die Frage