file upload make directory issue

240
April 18, 2017, at 3:01 PM

Actually While uploading a file I am creating directory with time() and also saving folder name along filename to the database. This is working fine in adding but in editing if user without changing any files and submit means it is creating again folder and filename actually it should not create a folder if user does not change if user change files means it should create new folder otherwise no. Please help me how to resolve this.

Below is code, Adding Code,

    if($_FILES['event_image']['name']!=""){
                      $folderName = $_POST['event_name'].time();
                      $this->session->set_userdata("folderName",$folderName);
                      $pathToUpload = 'images/events/' . $folderName;
                      $old = umask(0);
                      if ( ! file_exists($pathToUpload) )
                      {
                          $create = mkdir($pathToUpload, 0777,true);
                          chmod($pathToUpload,0755,true);
                          if ( ! $create )
                          return;
                      }
                      umask($old);
                    }
                    $config['upload_path'] = $pathToUpload;
                    $config['allowed_types'] = 'gif|jpg|png';
                    $config['max_size'] = '9999';
                    $cofig['overwrite'] = 1;
                    $this->load->library('upload', $config);
                    if ( ! $this->upload->do_upload('event_image'))
                    {
                        echo "failed";
                    }
                    else
                    {
                      $data = $this->upload->data();
                      $eventimage = $data['file_name'];
                    }if($_FILES['event_image']['name']!=""){
                      $folderName = $_POST['event_name'].time();
                      $this->session->set_userdata("folderName",$folderName);
                      $pathToUpload = 'images/events/' . $folderName;
                      $old = umask(0);
                      if ( ! file_exists($pathToUpload) )
                      {
                          $create = mkdir($pathToUpload, 0777,true);
                          chmod($pathToUpload,0755,true);
                          if ( ! $create )
                          return;
                      }
                      umask($old);
                    }
                    $config['upload_path'] = $pathToUpload;
                    $config['allowed_types'] = 'gif|jpg|png';
                    $config['max_size'] = '9999';
                    $cofig['overwrite'] = 1;
                    $this->load->library('upload', $config);
                    if ( ! $this->upload->do_upload('event_image'))
                    {
                        echo "failed";
                    }
                    else
                    {
                      $data = $this->upload->data();
                      $eventimage = $data['file_name'];
                    }
$event_name = ucwords(strtolower($this->input->post('event_name')));
                $event_image = $folderName.'/'.$eventimage;
                $description = $this->input->post('event_description');
                $start_date = $this->input->post('start_date');
                $end_date = $this->input->post('end_date');
                $additional_images = $additional_eventimages;
                $sdescription = $this->input->post('short_description');

    $eventInfo = array('event_name'=>$event_name, 'event_image'=>$event_image, 'event_description'=>$description, 'start_date'=> $start_date,
                                    'start_date'=>$start_date,'end_date'=>$end_date,'additional_images'=> $additional_images,'short_description'=>$sdescription,);

Edit Code,

$folderName = $_POST['event_name'].time();
                $pathToUpload = 'images/events/' . $folderName;
                $old = umask(0);
                if ( ! file_exists($pathToUpload) )
                {
                    $create = mkdir($pathToUpload, 0777,true);
                    // chmod($pathToUpload,0755,true);
                    if ( ! $create )
                    return;
                }
                umask($old);
$config['upload_path'] = $pathToUpload;
                $config['allowed_types'] = 'gif|jpg|png';
                $config['max_size'] = '9999';
                $cofig['overwrite'] = 1;
                $this->load->library('upload', $config);
                if(isset($_POST['image_exists']) && $_POST['image_exists'] != '')
                $temp_image = $_POST['image_exists'];
                if(isset($_FILES['event_image']['name'])  && $_FILES['event_image']['name'] != ""){
                  if ( ! $this->upload->do_upload('event_image'))
                  {
                    // $data = $this->upload->data();
                    echo "failed";
                    // echo 
                  }
                  else
                  {
                    $data = $this->upload->data();
                    $eventimage = $data['file_name'];
                  }
                }
$event_name = ucwords(strtolower($this->input->post('event_name')));
                $event_image = $folderName.'/'.$eventimage;

                $description = $this->input->post('event_description');
                $start_date = $this->input->post('start_date');
                $end_date = $this->input->post('end_date');
                // if($additional_eventimages!=""){
                $additional_images = implode(',',$additional_eventimages);
                $sdescription = $this->input->post('short_description');
                // }
                // else
                // {
                //     $additional_images = implode(',',$additional_eventimages);
                // }                
                $eventInfo = array('event_name'=>$event_name, 'event_image'=>$event_image, 'event_description'=>$description, 'start_date'=> $start_date,
                                    'start_date'=>$start_date,'end_date'=>$end_date,'additional_images'=> $additional_images,'short_description'=>$sdescription,);
Rent Charter Buses Company
READ ALSO
inserting data into database using php

inserting data into database using php

i have used this code to insert the data to database[phpmyadmin] but it's not working what to do

273
php/sql : don't echo show data correctly (solved)

php/sql : don't echo show data correctly (solved)

i have a problem with my php and sql codeI trying to make code that when i enter some data that related with the database, the output should show 'zero' if the row user_designid equal to 0 and if vice versa it will show 'one'

254
PHP ERROR “unexpected header”

PHP ERROR “unexpected header”

After trying to debug I found a file that had this error in it:

637
Laravel Auth::Attempt Assuming Separate Password Table

Laravel Auth::Attempt Assuming Separate Password Table

I am storing my User table, and Password table separatelyThe rationale for this is to prevent accidental leak of the hashed password, should the user accidentally place the password parameter in the $visible variable of User

324