我有以下代码用于文件上传。这正在我的本地主机中使用IP地址。但是在Hostinger的共享托管中不起作用。它显示以下错误。请帮忙。
未定义索引:文件{“ exception”:“ [对象](ErrorException(code:0):未定义索引:文件位于/home/u766753775/domains/nammoor.online/public_html/laravel/routes/web.php: 527)
IONIC 4:
async CameraImageUploadwithoutCrop() {
await this.imagePicker.getPictures({ maximumImagesCount: 1, outputType: 0 }).then((results) => {
for (const image of results) {
console.log('Image URI: ' + image);
const fileTransfer: FileTransferObject = this.transfer.create();
const uploadOpts: FileUploadOptions = {
fileKey: 'file',
fileName: image.substr(image.lastIndexOf('/') + 1)
};
fileTransfer.upload(image, 'https://nammoor.online/post/uploadImage', uploadOpts)
// fileTransfer.upload(image, 'http://191.168.01.10:8000/post/uploadImage', uploadOpts)
.then((data) => {
console.log(data);
this.respData = JSON.parse(data.response);
console.log(this.respData);
this.imageUrl = this.respData.fileUrl;
}, (err) => {
console.log(err);
});
}
}, (err) => { console.log(err); });
}
PHP:
Route::post('/post/uploadImage', function (Request $request) {
// Route::post('image-upload', )->name('image.upload.post');
$connection = OpenCon();
$request = Request::instance(); // Access the instance
$content = $request->getContent(); // Get its content
// p($request);
$date = date('dmYHis');
$target_path = "uploads/images/".$date.".jpg";
try {
//if (move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
if (move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
//$fileUrl = "http://191.168.01.10:8000/".$target_path."";
$fileUrl = "https://nammoor.online/".$target_path."";
$eRes = json_encode('{ "fileUrl": "'.$fileUrl.'"}', true);
p($fileUrl);
$msg = json_decode($eRes ,true);
p($msg);
return $msg;
} else {
echo $target_path;
}
}
}, (err) => { console.log(err); });
}