上传图片在codeigniter,是userfile需要? [英] uploading images in codeigniter, is userfile required?
问题描述
我使用下面的功能将我的映像文件上传到我的服务器(Localhost)。这是很好,正在上传图像。但我需要两个图像字段,因此,一旦点击提交按钮,这两个图像都应该上传。我使用此处 Codeigniter多文件上传 描述的功能,但它
一个PHP错误遇到
严重性:警告
消息:is_uploaded_file()期望参数1为字符串,数组给定
文件名:libraries /上传。 php
行号:161
我不明白错误。
我用来上传单个图片的函数是
function do_upload()
{
$ config ['upload_path'] ='./uploads/';
$ config ['allowed_types'] ='jpeg | png | gif';
$ config ['max_size'] ='0';
$ config ['max_width'] ='0';
$ config ['max_height'] ='0';
$ this-> load-> library('upload',$ config);
if(!$ this-> upload-> do_upload())
{
$ error = array('error'=> $ this-> upload - > display_errors());
//失败显示错误
}
else
{
//成功
}
}
此外,我还想问我可以更改我选择的输入字段名称。即我总是需要实现< input type =filename =userfile/>
。是否可以更改名称?
您必须循环显示已提供的链接中上传的文件。
function do_upload ){
$ config ['upload_path'] ='./uploads/';
$ config ['allowed_types'] ='jpeg | png | gif';
$ config ['max_size'] ='0';
$ config ['max_width'] ='0';
$ config ['max_height'] ='0';
$ this-> load-> library('upload',$ config);
foreach($ _FILES as $ key => $ value){
if(!empty($ value ['tmp_name'])){
if(!$ this-> upload-> do_upload($ key)){
$ error = array('error'=> $ this-> upload-> display_errors ;
//失败显示错误
} else {
// success
}
}
}
}
并尝试使用HTML:
< input type =filename =file1id =file_1/>
< input type =filename =file2id =file_2/>
< input type =filename =file3id =file_3/>
您可以随意更改输入字段的名称。
I am using the function below to upload my image files to my server(Localhost). It is fine and image is being uploaded. But I need two image fields and hence both the images should be uploaded once the submit button is clicked. I used the function described here Codeigniter multiple file upload , but it is not working.
I get this error message
A PHP Error was encountered
Severity: Warning
Message: is_uploaded_file() expects parameter 1 to be string, array given
Filename: libraries/Upload.php
Line Number: 161
Well I cannot understand where the error is. The function that I am using to upload single image is
function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'jpeg|png|gif';
$config['max_size'] = '0';
$config['max_width'] = '0';
$config['max_height'] = '0';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
//failed display the errors
}
else
{
//success
}
}
In addition I also like to ask can i change the input field name of my choice. i.e i always need to implement <input type="file" name="userfile"/>
. Is it possible to change the name? I tried changing it and I get the message No file was selected, so that must mean that I cannot change it.
You have to loop through the uploaded files like it is shown in your provided link.
function do_upload() {
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'jpeg|png|gif';
$config['max_size'] = '0';
$config['max_width'] = '0';
$config['max_height'] = '0';
$this->load->library('upload', $config);
foreach ($_FILES as $key => $value) {
if (!empty($value['tmp_name'])) {
if ( ! $this->upload->do_upload($key)) {
$error = array('error' => $this->upload->display_errors());
//failed display the errors
} else {
//success
}
}
}
}
And try using HTML like this:
<input type="file" name="file1" id="file_1" />
<input type="file" name="file2" id="file_2" />
<input type="file" name="file3" id="file_3" />
You can change the names of the input fields as you like.
这篇关于上传图片在codeigniter,是userfile需要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!