在php中从用户处获取一个文件,并将其发送到flask服务器,而不保存它
我试图通过php curl将一个文件发送到flask服务器,我做错了什么 以下是场景: -用户访问我的php应用程序并上载excel文件 -我的应用程序通过php\u curl将文件发送到(python)flask应用程序 php代码=========================在php中从用户处获取一个文件,并将其发送到flask服务器,而不保存它,php,python-3.x,curl,post,flask,Php,Python 3.x,Curl,Post,Flask,我试图通过php curl将一个文件发送到flask服务器,我做错了什么 以下是场景: -用户访问我的php应用程序并上载excel文件 -我的应用程序通过php\u curl将文件发送到(python)flask应用程序 php代码========================= public function actiongetFileSendIt(){ if (function_exists('curl_file_create')) { $cFile = curl_fi
public function actiongetFileSendIt(){
if (function_exists('curl_file_create')) {
$cFile = curl_file_create($_FILES['file']['tmp_name'],$_FILES['file']['type'],'file');
} else {
$cFile = '@' . realpath($_FILES['file']['tmp_name'].';filename='.$_FILES['file']['name'].';type='.$_FILES['file']['type']);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://0.0.0.0:8000/api/pos/import");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $cFile);
$result = curl_exec($ch);
curl_close($ch);
echo "<pre>";print_r($result);echo "</pre>";exit("Ends Here");
}
curl -X POST http://0.0.0.0:8000/api/pos/import -H 'cache-control: no-cache' -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' -H 'postman-token: 73b974f1-3e3f-713d-2a34-a1abeb3d9a80' -F 'file=@/home/anubavam/Downloads/Corrected_Regulations MA YOGA.xlsx'
{
"success": "Plan of study import completed"
}
================日志=============
public function actiongetFileSendIt(){
if (function_exists('curl_file_create')) {
$cFile = curl_file_create($_FILES['file']['tmp_name'],$_FILES['file']['type'],'file');
} else {
$cFile = '@' . realpath($_FILES['file']['tmp_name'].';filename='.$_FILES['file']['name'].';type='.$_FILES['file']['type']);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://0.0.0.0:8000/api/pos/import");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $cFile);
$result = curl_exec($ch);
curl_close($ch);
echo "<pre>";print_r($result);echo "</pre>";exit("Ends Here");
}
curl -X POST http://0.0.0.0:8000/api/pos/import -H 'cache-control: no-cache' -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' -H 'postman-token: 73b974f1-3e3f-713d-2a34-a1abeb3d9a80' -F 'file=@/home/anubavam/Downloads/Corrected_Regulations MA YOGA.xlsx'
{
"success": "Plan of study import completed"
}
工作曲柱
request.files 3 ImmutableMultiDict([('file', <FileStorage: 'Corrected_Regulations MA YOGA.xlsx' ('application/octet-stream')>)])
python日志
request.files 1 ImmutableMultiDict([])
if (function_exists('curl_file_create')) {
$cFile = curl_file_create($_FILES['file']['tmp_name']);
} else {
$cFile = '@' . realpath($_FILES['file']['tmp_name']);
}
$post = array('file'=> $cFile);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://0.0.0.0:8000/api/pos/import");
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result=curl_exec ($ch);
curl_close ($ch);
问题1:如何在php$\u文件中从用户处获取文件并将其转换为curl post。
问题2:如何使用{'file':/path/or/which/from/question1}这样的键值对将php curl post制作到flask我找到了解决方案。如果有人想处理这种情况