Curl Загрузка файла PHP

Эй, пытаюсь опубликовать файл с помощью curl, и все работает отлично. У меня одна проблема. Я не могу объявить свой файл вне функции post_file (). Я вызываю эту функцию в своем приложении много раз, поэтому хочу, чтобы ее можно было использовать повторно.

Итак, это работает:

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;
}

Однако это не работает:

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;
}

Есть идеи? Ура.

5
задан bradley 8 October 2010 в 16:47
поделиться