[英]How to get parameter of ng2-file-upload with endback?
I want to get parameter with php. 我想用php获取参数。 I try with my code but it still not work save into folder (parameter) this is post http image:
我尝试使用我的代码,但它仍然无法保存到文件夹(参数)这是发布http图像:
Ionic framework 离子框架
this.uploader.onBeforeUploadItem = (item: any) => {
this..uploader.options.additionalParameter = {
folder : this.herb_id <---- my parameter folder name
};
endback(php) endback(PHP)
<?php
header('Access-Control-Allow-Origin', '*');
header('Access-Control-Allow-Methods', 'POST');
header('Access-Control-Allow-Headers', 'Content-Type, Content-Range, Content-Disposition, Content-Description,X-Requested-With');
header('Access-Control-Allow-Credentials', true);
if (isset($_FILES['file'])) {
/------------- folder name --------------------------//
$path = 'uploads/';
$path .=$_FILES['options']['additionalParameter']['folder']; <---- folder name
$path .= '/';
$originalName = $_FILES['file']['name'];
$ext = '.'.pathinfo($originalName, PATHINFO_EXTENSION);
$generatedName = md5($_FILES['file']['tmp_name']).$ext;
//$filePath = $path.$generatedName;
$filePath = $path.$generatedName;
if (!is_writable($path)) {
echo json_encode(array(
'status' => false,
'msg' => 'Destination directory not writable.'
));
exit;
}
i can solve it as this code 我可以解决它作为这个代码
for ionic 用于离子
this.fileField.uploader.onBuildItemForm = (fileItem, form) => {
form.append('folder', String(this.herb_id));
return { fileItem, form };
};
for php 对于PHP
/------------- folder name --------------------------//
$path = 'uploads/';
$path .=$_POST['folder']; <---- folder name
$path .= '/';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.