0
votes

when uploading an image to the server using cakephp

$this->Model->Behaviors->attach('ImageUpload', Configure::read('photo.files'));

photo uploaded successfully, and the database fields also

but shows following error instead of returning to index page.


Notice (8): Undefined index: class [CORE\cake\libs\model\behaviors\upload.php, line 104]

Notice (8): Undefined index: class [CORE\cake\libs\model\behaviors\upload.php, line 107]

Warning (2): Cannot modify header information - headers already sent by (output started at E:\umoorthy_105act10\projects\dev1base\core\cake\basics.php:111) [CORE\cake\libs\controller\controller.php, line 614]


wat to do?

2
What behaviour are you actually using? If it is MeioUpload this link might help: mail-archive.com/[email protected]/msg76460.htmlharpax
im using image upload behaviour..udhaya
Any links to that specific behavior? A cursory Google search didn't bring up anything useful.deceze

2 Answers

0
votes

Cake has already wrote where to look for a problem

Configure::read('photo.files')

do following to check if everything is ok

pr(Configure::read('photo.files'))
0
votes
public  function uploadFilesIphone($folder, $formdata, $replace , $itemId = null) {
                // setup dir names absolute and relative    echo "<pre>";       print_r($formdata);     exit;

            $folder_url = WWW_ROOT.$folder;
            $rel_url = $folder; //echo

                // create the folder if it does not exist
                if(!is_dir($folder_url)) {
                    mkdir($folder_url);
                }

                // if itemId is set create an item folder
                if($itemId) {
                    // set new absolute folder
                    $folder_url = WWW_ROOT.$folder.'/'.$itemId; 
                    // set new relative folder
                    $rel_url = $folder.'/'.$itemId;
                    // create directory
                    if(!is_dir($folder_url)) {
                        mkdir($folder_url);
                    }
                }

                // list of permitted file types, this is only images but documents can be added
                $permitted = array('image/gif','image/jpeg','image/pjpeg','image/png','application/octet-stream');

                // loop through and deal with the files;

                $key = array();
                $value = array();
                foreach($formdata as  $key => $value) 
                {   
                    if($key == is_array($value))
                    {
                        $filename = str_replace(".", $replace , $value['name']);
                    }   

                    // replace spaces with underscores

                    // assume filetype is false
                    $typeOK = false;
                    // check filetype is ok

                    foreach($permitted as $type) 
                    {   
                        if($key == is_array($value))
                        {
                            if($type == $value['type']) 
                            {
                                $typeOK = true;
                                break;
                            }
                        }   
                    }
                    // if file type ok upload the file

                    if($typeOK) {
                        // switch based on error code
                        if($key == is_array($value))
                        {
                            switch($value['error']) 
                            {
                            case 0:
                                // check filename already exists
                                if(!file_exists($folder_url.'/'.$filename)) 
                                {
                                    // create full filename
                                    $full_url = $folder_url.'/'.$filename;
                                    $url = $rel_url.'/'.$filename;

                                    // upload the file
                                    if($key == is_array($value))
                                    {
                                        $success = move_uploaded_file($value['tmp_name'], $url);
                                    }
                                } 
                                else 
                                {
                                    // create unique filename and upload file
                                    //  ini_set('date.timezone', 'Europe/London');
                                    $now = date('Y-m-d-His');
                                    $full_url = $folder_url.'/'.$now.$filename;
                                    $url = $rel_url.'/'.$now.$filename;
                                    if($key == is_array($value))
                                    {   
                                        $success = move_uploaded_file($value['tmp_name'], $url);
                                    }
                                }
                                // if upload was successful
                                if($success) 
                                {
                                    // save the url of the file
                                    $result['urls'][] = $url;
                                } 
                                else 
                                {
                                    $result['errors'][] = "Error uploaded $filename. Please try again.";
                                }
                                break;
                            case 3:
                                // an error occured
                                $result['errors'][] = "Error uploading $filename. Please try again.";
                                break;
                            default:
                                // an error occured
                                $result['errors'][] = "System error uploading $filename. Contact webmaster.";
                                break;
                        }
                    } 
                    elseif($value['error'] == 4) 
                    {
                        // no file was selected for upload
                        $result['nofiles'][] = "No file Selected";
                    } 
                    else 
                    {
                        // unacceptable file type
                        $result['errors'][] = "$filename cannot be uploaded. Acceptable file types: gif, jpg, png.";
                    }
                  }
                }
            return $result;
            }