У меня проблема в прикрепленном файле с помощью php.Если я обращаюсь к файлу php напрямую, никаких проблем не возникает.Но если я внедряю в свой веб-сервис, он не работает.Вот файл .php.Это не полный мой php-код, просто часть для прикрепления файла
$file = "..\output\yunike@gmail.com\dump_bib_id_ayt_texts.sql";
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment;
filename="'.basename($file).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}else{
return "file empty";
}
, вот мой root.php.Я использую тонкий фреймворк.
$app->post('/prosesData',function (Request $request, Response $response, array $args){
$data = $request->getParsedBody();
$obj = new ProsesData();
$body = $obj->proses($data['file1'],$data['file2'],$data['email']);
$response->getBody()->write(json_encode($body));
$newResponse = $response->withHeader('Content-type', 'application/json')->withHeader('Access-Control-Allow-Origin', '*');
return $newResponse;
});
Я вызываю функцию в php с помощью ajax
$.post('http://localhost:8800/public/prosesData', {'file1': file1, 'file2': file2, 'email': email}, function(data){
$('#hasil tr:last').remove();
$(".hasil").append("<tr><td>"+id+"</td><td>"+data+" </td>
<td><button id='checkFile1'>LANJUTKAN MEMECAH PERKATA FILE 1</button></td></tr>");
id++;
});
результат не прикрепить файл, но показать содержание текста, который я хочу прикрепить.Почему это случилось?спасибо