first please be gentle im a really big begginer.
Ok im making a real estate site and i really have no clue, i tried several things but i cant make it work.
My problem is when i add a new real estate to the site, the system generates an unique 7 characters long numeric string and inserts it in to the database.
So when i upload an image i would like that the system creates a folder named with this unique 7 characters long numeric string and place the images there.
here is my controller
<?php
class ihirdet extends CI_Controller
{
function index()
{
$this->load->view("header");
$this->form_validation->set_rules('cim', 'Cím', 'min_length[10]|max_length[100]');
$this->form_validation->set_rules('htipus', 'Hirdetés típusa', 'required');
$this->form_validation->set_rules('itipus', 'Ingatlan típusa', 'required');
$this->form_validation->set_rules('iallapot', 'Ingatlan állapota', 'required');
$this->form_validation->set_rules('jaras', 'Járás', 'required');
$this->form_validation->set_rules('telepules', 'Telepules', 'required');
$this->form_validation->set_rules('utca', 'Utca', 'required');
$this->form_validation->set_rules('hazszam', 'Házszám', 'required|numeric');
$this->form_validation->set_rules('emelet', 'Emelet', 'numeric');
$this->form_validation->set_rules('telekterulet', 'Telekterület', 'numeric');
$this->form_validation->set_rules('alapterulet', 'Alapterület', 'numeric');
$this->form_validation->set_rules('ingatlanar', 'Ingatlan ára', 'required|numeric');
$this->form_validation->set_rules('penznem', 'Pénznem', 'required');
$this->form_validation->set_rules('epitesev', 'Építés éve', 'numeric');
$this->form_validation->set_rules('szoba', 'Szoba', 'numeric');
$this->form_validation->set_rules('felszoba', 'Félszoba', 'numeric');
$this->form_validation->set_rules('futes', 'Fűtés', 'required');
//$this->form_validation->set_rules('userfile', 'Kép', 'callback_kep_ellenor');
$this->load->model('hirdetes_model');
if($this->form_validation->run() !== FAlSE)
{
$this->hirdetes_model->kuld();
// redirect(base_url() . 'elado/adatlap/' . $this->input->post('azonosito'));
} else {
$this->load->model('hirdetes_model');
$data['felh_inf'] = $this->hirdetes_model->felh_info();
$this->load->view("ihirdet_sablon", $data);
}
$this->load->view("footer");
}
}
?>
I was testing, and i was able to upload only one image and create the folder.
My question is, how can i implant a multi imageupload in to my index function, with createing the folder.
And a validation so only create the folder and upload the images in it when the image input has a value, but if the user didnt fill out the form correctly, but the image is fine still dont create the folder and dont upload the image.
Please dont misunderstand me, i dont want anybody to write the codes for me, i just want a more expreienced developer to share his thougts how would he make it, no codes just share the idea, and i will try to make it by my self.
You could try something like this:
function tester($yourUniqueId){ $this->load->library('upload'); for($i=0; $i<count($_FILES); $i++) { $_FILES['userfile']['name'] = $_FILES['filename']['name'][$i]; $_FILES['userfile']['type'] = $_FILES['filename']['type'][$i]; $_FILES['userfile']['tmp_name'] = $_FILES['filename']['tmp_name'][$i]; $_FILES['userfile']['error'] = $_FILES['filename']['error'][$i]; $_FILES['userfile']['size'] = $_FILES['filename']['size'][$i]; $config['file_name'] = $yourUniqueId.'/test_'.$i; $config['upload_path'] = './public/uploads/'; $config['allowed_types'] = 'jpg|jpeg|gif|png'; $config['max_size'] = '0'; $config['overwrite'] = FALSE; $this->upload->initialize($config); if($this->upload->do_upload()) { $error += 0; }else{ $error += 1; } } if($error > 0){ return FALSE; }else{ return TRUE; } }Hope it helps