Привет, пытаюсь опубликовать файл, используя 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;
}
Есть идеи? Приветствия.