我一直在尝试使用codeigniter 1.7进行多文件上传。我有至少可以说的问题!
我知道它是一个旧版本,但这是我必须使用的版本。
我可以循环$ _FILES数组并上传每个数组吗?它似乎不起作用。
这是我所拥有的?
$dir_name = $this->input->post('dir');
$file_path = "./system/application/views/courses/course/";
$full_file_path = $file_path . $dir_name;
if (!file_exists($full_file_path)) {
mkdir($full_file_path, 0777, true);
}
$config['upload_path'] = $full_file_path;
$config['allowed_types'] = 'php|js|html';
$this->load->library('upload');
foreach ($_FILES as $files => $fileObject) //
{
if (!empty($fileObject['name']))
{
$this->upload->initialize($config);
if (!$this->upload->do_upload($files))
{
$errors = $this->upload->display_errors();
}
else
{
echo "It worked";
}
}
}
这可能吗?
这段代码可以运行,但是不上传文件吗?
参考方案
希望这会有所帮助
$name_array=array();
$count = count($_FILES['userfile']['size']);
foreach($_FILES as $key => $value)
{
for ($s = 0; $s < $count; $s++)
{
$_FILES['userfile']['name'] = $value['name'][$s];
$_FILES['userfile']['type'] = $value['type'][$s];
$_FILES['userfile']['tmp_name'] = $value['tmp_name'][$s];
$_FILES['userfile']['error'] = $value['error'][$s];
$_FILES['userfile']['size'] = $value['size'][$s];
$config['upload_path'] = "uploads/item_images/itemimage/original/";
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '8000';
$config['max_width'] = '10240';
$config['max_height'] = '7680';
$this->load->library('upload', $config);
if ($this->upload->do_upload("image"))
{
$data = $this->upload->data();
if ($this->image_moo->errors)
{
print $this->upload->display_errors();
}
else
{
$name_array[] = $data['file_name'];
} } } }
PHP:对数组排序 - php请如何排序以下数组Array ( 'ben' => 1.0, 'ken' => 2.0, 'sam' => 1.5 ) 至Array ( 'ken' => 2.0, 'sam' => 1.5, 'ben' =&…
PHP:不推荐使用password_hash的'salt'选项 - php我正在使用密码哈希进行注册。我需要手动创建Salt,以下是我使用的代码:$options = [ 'cost' => 11, 'salt' => mcrypt_create_iv(22, MCRYPT_DEV_URANDOM) ]; $password = password_hash( $this->…
PHP-全局变量的性能和内存问题 - php假设情况:我在php中运行一个复杂的站点,并且我使用了很多全局变量。我可以将变量存储在现有的全局范围内,例如$_REQUEST['userInfo'],$_REQUEST['foo']和$_REQUEST['bar']等,然后将许多不同的内容放入请求范围内(这将是适当的用法,因为这些数据指的是要求自…
PHP strtotime困境 - php有人可以解释为什么这在我的服务器上输出为true吗?date_default_timezone_set('Europe/Bucharest'); var_dump( strtotime('29.03.2015 03:00', time()) === strtotime('29.03.2015 04:00…
php-casperjs获取内部文本 - php我正在为casperjs使用php包装器-https://github.com/alwex/php-casperjs我正在网上自动化一些重复的工作,我需要访问一个项目的innerText,但是我尚不清楚如何从casperjs浏览器访问dom。我认为在js中我会var arr = document.querySelector('label.input…