我在文件上传时遇到问题这是我的多个文件的代码,附加输入字段提到客户名称
@NgModule({
imports: [CommonModule, RouterModule, MenubarModule, GalleriaModule, InputTextModule, PanelModule, ButtonModule,
DropdownModule, DialogModule, AccordionModule, CalendarModule, SelectButtonModule, CheckboxModule,
ProgressBarModule, DataTableModule],
declarations: [ ErrorMessagesComponent, FoodDashboardComponent ],
exports: [ CommonModule, ReactiveFormsModule, HttpModule, RouterModule,
MenubarModule, GalleriaModule, InputTextModule, PanelModule, ButtonModule, DropdownModule, DialogModule, AccordionModule, CalendarModule,
SelectButtonModule, CheckboxModule, DataTableModule, ProgressBarModule, ErrorMessagesComponent, FoodDashboardComponent ]
})
export class SharedModule {
//
static forRoot(): ModuleWithProviders {
return {
ngModule: SharedModule,
providers: [SettingsService, AppMenuService, AuthorizationService, LoginService, RegisterService, ThemeService, ValidationService,
NutritionixService, AuthGuardService, CalculationService, ChallengeService ]
};
}
}
我有多个要上传的文件,所以我使用foreach。 这是$ _FILES输出 两张图片上传
$titles=$_REQUEST['doc_title'];
$tmp_names=$_FILES['filename']['tmp_name'];
$requestid=$_REQUEST['Reqno'];
//echo $_SERVER['HTTP_HOST'];
//echo $_SERVER['REQUEST_URI']; die;
$url= 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$upload_dir=str_replace('/index.php','/',$url);
$time = time();
$arraData=array();
$filearray=array();
foreach($_FILES['filename']['name'] as $key=>$value){
$arraData[$key]['doc_title']=$titles[$key];
$arraData[$key]['file_name']=$time.$value;
$arraData[$key]['tmp_name']=$tmp_names[$key];
$arraData[$key]['req_id']=$requestid;
$pathAndName = $upload_dir."temp/Moredocument/" . $time.$value;
$move_files=move_uploaded_file($tmp_names[$key], $pathAndName);
}
请帮助我的错误。
答案 0 :(得分:2)
要上传文件,我们需要传递文件的绝对网址。
您在这里使用了
$url= 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$upload_dir=str_replace('/index.php','/',$url);
这将为您提供http://
网址,以便您无法移动文件。
$titles=$_REQUEST['doc_title'];
$tmp_names=$_FILES['filename']['tmp_name'];
$requestid=$_REQUEST['Reqno'];
//This is the roor url you can use __DIR__ or dirname(__FILE__)
$upload_dir= '/';
$time = time();
$arraData=array();
$filearray=array();
foreach($_FILES['filename']['name'] as $key=>$value) {
$arraData[$key]['doc_title']=$titles[$key];
$arraData[$key]['file_name']=$time.$value;
$arraData[$key]['tmp_name']=$tmp_names[$key];
$arraData[$key]['req_id']=$requestid;
//Make sure you have created this all directories
$pathAndName = $upload_dir."temp/Moredocument/" . $time.$value;
$move_files=move_uploaded_file($tmp_names[$key], $pathAndName);
}
答案 1 :(得分:0)
您当前文件的网址是什么,以及您尝试使用
做什么$arraData[$key]['doc_title']=$titles[$key];
$arraData[$key]['file_name']=$time.$value;
$arraData[$key]['tmp_name']=$tmp_names[$key];
$arraData[$key]['req_id']=$requestid;
$pathAndName = $upload_dir."temp/Moredocument/" . $time.$value;
move_uploaded_file($tmp_names[$key], $pathAndName);