[eluser]nemo1112[/eluser]
Hi coder
I have try to upload 4 image file at the same time.
But I have problem with file name when upload finish.
I have try many time and check in upload folder there have 4 image i upload
but file name change like this.file name change to first image name i upload.
Please help. Thank you.
Output like this
File Name: FatboySlim_-_Why_try_harder4.jpg
File Name: FatboySlim_-_Why_try_harder4.jpg.jpg
File Name: FatboySlim_-_Why_try_harder4.jpg.jpg.jpg
File Name: FatboySlim_-_Why_try_harder4.jpg.jpg.jpg.jpg
Controllers
Code:
<?php
class Upload extends Controller {
function Upload() {
parent::Controller();
// $this->load->helper('form');
}
function index() {
$this->load->view('upload_form');
}
function doUpload() {
$config['upload_path'] = 'uploads/';
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['max_size'] = '1000';
$config['max_width'] = '1920';
$config['max_height'] = '1280';
$this->load->library('upload', $config);
foreach($_FILES as $key => $value)
{
if(!$this->upload->do_upload($key)) echo $this->upload->display_errors();
else {
$fInfo = $this->upload->data();
$this->_createThumbnail($fInfo['file_name']);
$data['uploadInfo'] = $fInfo;
$this->load->view('upload_success', $data);
}
}
}
}
View upload_form.php
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div id="container">
<h2>Upload an Image </h2>
<?php echo form_open_multipart('upload/doUpload'); ?>
<?php
if(isset($upload_message))
{
echo $upload_message;
}
?>
<?php $i = 4; for ($j = 1; $j <= $i; $j++): ?>
<div class="form_element">
<label for="photo<?=$j?>">Photo N°<?=$j?></label>
<?=form_upload(array('name' => 'photo'.$j,
'id' => 'photo'.$j,
'size' => '36'))?>
</div>
<?php endfor ?>
<p><input type="submit" value="Submit" name="submit" /></p>
<?php echo form_close(); ?>
</div>
</body>
</html>
View upload_success.php
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
dt {
font-weight: bold;
float: left;
padding-right: 1em;
}
</style>
</head>
<body>
<div id="container">
<p>Congratulations. Your photo has been uploaded successfully. </p>
<dl>
<dt>File Name: </dt>
<dd> <?= $uploadInfo['file_name']; ?> </dd>
<dt>File Size: </dt>
<dd> <?= $uploadInfo['file_size']; ?> </dd>
<dt> File Extension: </dt>
<dd> <?= $uploadInfo['file_ext']; ?> </dd>
</dl>
<img alt="Your Image" src="<?= base_url() . 'uploads/' . $uploadInfo['file_name'];?>" />
<img alt="Your Thumbnail" src="<?= base_url() . 'uploads/thumb/' . $thumbnail_name;?>" />
</div>
</body>
</html>