Welcome Guest, Not a member yet? Register   Sign In
Upload Class Problem - multiple image file uploads go south
#1

[eluser]corkscrew[/eluser]
Hi all

I have a problem with a multiple upload of several image files (jpg). Creating a new db table entry all appears to go well until I check the target upload directory - the first file that I upload is ok with name 'Image.jpg' but all of the rest of the files are named the same with multiple extensions 'Image.jpg.jpg', 'Image.jpg.jpg.jpg' etc. I am hoping that this is only a symptom of me being hit with a touch of "duh!!"

Any enlightenment you could provide would be appreciated

I am using apache 2.2, PHP 5.2, and CI 1.7.2 on an XP Win Box

code as follows


Controller function

<?php
function create(){
if ($this->input->post('name')){
$this->MProperties->addProperty();
$this->session->set_flashdata('message','Property created');
redirect('admin/properties/index','refresh');
}else{
$data['title'] = "Create Property";
$data['main'] = 'admin/admin_properties_create';
$data['categories'] = $this->MCats->getCategoriesDropDown();
$this->load->vars($data);
$this->load->view('admin/dashboard');
}

?>

Excerpt from model

<?php

if ($_FILES){

$config['upload_path'] = './images/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '200';
$config['remove_spaces'] = true;
$config['overwrite'] = false;
$config['max_width'] = '0';
$config['max_height'] = '0';
$this->load->library('upload', $config);

if (strlen($_FILES['image']['name'])){
if(!$this->upload->do_upload('image')){
$this->upload->display_errors();
exit();
}
$image = $this->upload->data();

if ($image['file_name']){
$data['image'] = "/images/".$image['file_name'];
}
}


if (strlen($_FILES['thumbnail']['name'])){
if(!$this->upload->do_upload('thumbnail')){
$this->upload->display_errors();
exit();
}
$thumb = $this->upload->data();

if ($thumb['file_name']){
$data['thumbnail'] = "/images/".$thumb['file_name'];
}
}


if (strlen($_FILES['intimg1']['name'])){
if(!$this->upload->do_upload('intimg1')){
$this->upload->display_errors();
exit();
}
$intimg1 = $this->upload->data();

if ($intimg1['file_name']){
$data['intimg1'] = "/images/".$intimg1['file_name'];
}
}

$this->db->insert('properties', $data);
$new_product_id = $this->db->insert_id();
}

?>

excerpt from form

<?php

echo form_open_multipart('admin/properties/create');

echo "<p><label for='image'>Upload Image</label><br/>";
$data = array('name'=>'image','id'=>'image');
echo form_upload($data) ."</p>";

echo "<p><label for='thumbnail'>Upload Thumbnail</label><br/>";
$data = array('name'=>'thumbnail','id'=>'thumbnail');
echo form_upload($data) ."</p>";

echo "<p><label for='intimg1'>Upload Interior Image #1</label><br/>";
$data = array('name'=>'intimg1','id'=>'intimg1');
echo form_upload($data) ."</p>";

echo form_submit('submit','Create Property');
echo form_close();

?&gt;

result of running the above code is:
Images are uploaded to the indicated directory
image 1 is named IMAGE.JPG
image 2 is named IMAGE.JPG.JPG
image 3 is named IMAGE.JPG.JPG.JPG


Image is the same name for all images but the file sizes match the input file.
Same result is obtained when writing to the db.


print_r($_FILES); on the source data from the form

Array
(
[image] => Array
(
[name] => Blue hills.jpg
[type] => image/jpeg
[tmp_name] => C:\WINDOWS\Temp\phpAFE.tmp
[error] => 0
[size] => 28521
)

[thumbnail] => Array
(
[name] => Sunset.jpg
[type] => image/jpeg
[tmp_name] => C:\WINDOWS\Temp\phpAFF.tmp
[error] => 0
[size] => 71189
)

[intimg1] => Array
(
[name] => Water lilies.jpg
[type] => image/jpeg
[tmp_name] => C:\WINDOWS\Temp\phpB00.tmp
[error] => 0
[size] => 83794
)

)

but all of the saved uploads are the same name although the sizes actually match the input images

Blue_hills1.jpg 28 KB JPEG Image
Blue_hills1.jpg.jpg 70 KB JPEG Image
Blue_hills1.jpg.jpg.jpg 82 KB JPEG Image
Blue_hills1.jpg.jpg.jpg.jpg 104 KB JPEG Image
#2

[eluser]pistolPete[/eluser]
Please use [ code ] tags!

Have a look at this topic for a solution: File extension problem with upload




Theme © iAndrew 2016 - Forum software by © MyBB