Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
here image is not uploading.I think have some error
PHP
<?php
if ($this->request->is('post'))
    {
            $data = $this->request->data;
            pr($data);
            $multi = implode(",",$data['Form']['mcheckbox']);
            $data['Form']['mcheckbox']= $multi;

            if(!empty($data))
                {
                $image = $this->data['Form']['image'];
                pr($image);

                $imageTypes = array("image/gif", "image/jpeg", "image/png", "image/jpg");
                pr($imageTypes);

                $uploadFolder = "image";

               echo $uploadPath = WWW_ROOT . $uploadFolder;

                foreach ($imageTypes as $type) {
                pr($type);
                     if ($type == $image['type']) {

                        if ($image['error'] == 0) {

                            $imageName = $image['name'];

                            if (file_exists($uploadPath . '/' . $imageName)) {

                                $imageName = date('His') . $imageName;
                            }

                            $full_image_path = $uploadPath . '/' . $imageName;

                            if (move_uploaded_file($image['tmp_name'], $full_image_path)) {
                                $this->Session->setFlash('File saved successfully');
                                $this->set('imageName',$imageName);
                            } else {
                                $this->Session->setFlash('There was a problem uploading file. Please try again.');
                            }
                        } else {
                            $this->Session->setFlash('Error uploading file.');
                        }
                        break;
                    } else {
                        $this->Session->setFlash('Unacceptable file type');
                    }
                }
            }
            $mod = $this->Form->adddata($data);

            if($mod)
            {
                 $this->Session->setFlash(__('Your post has been saved.'));

                }
           else
            {
            $this->Session->setFlash(__('Unable to add your post.'));
            }

        }
    }

?>
Posted
Updated 13-Jan-15 1:54am
v5
Comments
ZurdoDev 13-Jan-15 7:48am    
You have code, do you have a question?
Sradhanjali Behera 13-Jan-15 7:55am    
here image is not uploading.I think have some error @RyanDev
Peter Leow 13-Jan-15 10:28am    
Have you set the enctype attribute to 'multipart/form-data' for your submitting form?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900