我想用php获取参数。我尝试使用我的代码,但将其保存到文件夹(参数)后仍然无法正常工作,这是发布的http图片:
离子框架
this.uploader.onBeforeUploadItem = (item: any) => {
this..uploader.options.additionalParameter = {
folder : this.herb_id <---- my parameter folder name
};
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;
}
答案 0 :(得分:0)
我可以解决此代码
离子性
this.fileField.uploader.onBuildItemForm = (fileItem, form) => {
form.append('folder', String(this.herb_id));
return { fileItem, form };
};
对于php
/------------- folder name --------------------------//
$path = 'uploads/';
$path .=$_POST['folder']; <---- folder name
$path .= '/';