Curl PHP File Upload
Hola, tratando de publicar un archivo usando curl y todo funciona muy bien. Tengo un problema No puedo declarar mi archivo fuera de mi función post_file (). Llamo a esta función en mi aplicación muchas veces, así que quiero que sea reutilizable.
Entonces esto funciona:
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;
}
Sin embargo, esto no:
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;
}
¿Algunas ideas? Salud.