2

I am trying to upload image,rename and add date with image ,after inserting record in database using cakephp.

if (move_uploaded_file($this->request->data['News']['image_url']['tmp_name'], WWW_ROOT. 'media/' . $this->request->data['News']['image_url']['name'])) {                           

            $this->request->data['News']['image_url'] = $this->request->data['News']['image_url']['name']. date('Y-m-d');

        }

It didn't upload image,rename image and add date with image,how can i correct my function to insert record ?

Gopal Sharma
  • 755
  • 1
  • 12
  • 25

1 Answers1

0

According to your problem I understood that you wanted to add date before image name when upload image and save that in database. It's simple. Use below code

if (move_uploaded_file($this->request->data['News']['image_url']['tmp_name'], WWW_ROOT. 'media/' . date('Y-m-d'). $this->request->data['News']['image_url']['name'])) {

  $this->request->data['News']['image_url'] = date('Y-m-d') . $this->request->data['News']['image_url']['name'];

      }
$this->Modelname->save($this->request->data['News']);

Here date adding before image name after location. In your previous code it was missing. So data was updated but image name were not changed in location. Your problem will solve now.

Lemon Kazi
  • 3,308
  • 2
  • 37
  • 67