[英]How to save multiple file name to a database?
i have a register form which user should upload their photo and other document ( for example doc-b, doc-b etc ). 我有一个注册表,用户应上传他们的照片和其他文档(例如doc-b,doc-b等)。
in my form I have something like 以我的形式我有类似
<input type="file" name="doc-a" id="doc-a">
<input type="file" name="doc-b" id="doc-b">
the "name" tag indicate what type of file it is, is it a document A, document B, photo of him or etc. “名称”标签指示文件的类型,是文件A,文件B,他的照片等。
in his profile page I want to link each individual file. 在他的个人资料页面中,我想链接每个单独的文件。 for example link to doc-b.
例如链接到doc-b。
so what I have in mind is create a table in DB to save each file name and their type ( form name tag ) . 所以我要记住的是在数据库中创建一个表来保存每个文件名及其类型(表单名称标签)。 but I don't know how can I do that
但我不知道该怎么办
here is the code to submit the form, save data to DB and upload the files : 这是提交表单,将数据保存到DB并上传文件的代码:
$this->member->register($this->input->post(NULL, TRUE));
$this->upload->do_upload('photo');
$this->upload->do_upload('doc-a');
$this->upload->do_upload('doc-b');
and then what I want to do is loop each files ( I don't know how should I do this ) 然后我想做的就是循环每个文件(我不知道该怎么做)
$member_id = $this->db->insert_id();
foreach ($_FILES as $member_files) {
if ($_FILES[] == 'photo') {
$file_type = 'photo';
}elseif ($_FILES['doc-a']) {
$file_type = 'doc-a';
$data = array(
'id_member' => $member_id,
'file_type' => $, // this should be the **name** tag
'file_name' => $, // this should be the file name
);
$this->db->insert('member_files', $data);
}
anyway, let me know if you have better way to do this. 无论如何,请告诉我您是否有更好的方法。 Thanks
谢谢
To check the extension of the file use this code 要检查文件的扩展名,请使用此代码
foreach($files as $file){
$name = $file->filename;
$info = new SplFileInfo($name);
$extension = $info->getExtension();
}
if($extension == "jpg" || $extension == "png" || $extension == "gif" || $extension == "jpeg") {
show your image
}else{
show other doc file
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.