I have fixed most issues after the upgrade but one I just can't seem to solve. I hope someone can help me. I created a few years ago this upload form/functionality in the admin section to give the admin user the possibility to upload images for a property in a region. The admin user select the Region, then the Property then browse over his drive to select a file, enter the image alt 'description' and then finally hit the Upload Image button. This form worked perfect in cakephp version 2.3.9. But after the upgrade it fails with "Internal Server error" in all Windows browsers, it looks like it has a problem with the 'temp' file location of this file I know they have changed so much in cakePHP i just wonder what setting/folder is just for this temp filename when you submit the form...
I checked the /user/local/apache/domlogs, I checked the /var/log/messages. I also checked in the /app/tmp/logs/ nothing... I have enabled the debug option. nothing.. I have tried to put a die(); on several places, but I am just puzzled, the form works as supposed I can't get anything faulty, but as soon as I press the button Upload Image. the error comes with blank screen and error: Internal Server error www.domain.com/admin/uploads.
View
-- I checked the /user/local/apache/domlogs, I checked the /var/log/messages. I also checked in the /app/tmp/logs/ nothing... I have enabled the debug option. nothing.. I have tried to put a die(); on several places, but I am just puzzled, the form works as supposed I can't get anything faulty, but as soon as I press the button Upload Image. the error comes with blank screen and error: Internal Server error www.domain.com/admin/uploads.
View
<br> <div class="upload form"> <fieldset> <?php echo $this->Session->flash(); ?> <legend><?php echo __('Admin - Upload Property Images'); ?></legend> <br><hr><br> <?php echo $this->Form->create('Upload', array('type' => 'file')); ?> <?php echo $this->Form->input('region_id', array('label' => 'Select Region:')); ?> <?php echo $this->Form->input('property_id', array('label' => 'Select Property:')); ?> <?php echo $this->Form->file('file'); ?> <?php echo $this->Form->input('description', array('label' => 'Image Alt = [Specify an alternate text for the image]:')); ?> <br> </fieldset> <?php echo $this->Form->submit(__('Upload Image', true)); ?> </div> <br>Controller
<?php App::uses('AppController', 'Controller'); App::uses('Folder', 'Utility'); App::uses('File', 'Utility'); class UploadsController extends AppController { public $helpers = array('Html', 'Form'); public $uses = array('Region','Property','PropertyImage'); public function admin_index() { $this->set('title_for_layout', 'Upload controller - '); // Retrieve the region list $this->set('regions', $this->Region->find('list', array( 'fields' => array('Region.id', 'Region.regionname'), 'order' => 'regionname', ))); // Retrieve the properties list $this->set('properties', $this->Property->find('list', array( 'fields' => array('Property.id', 'Property.ref', 'Property.description'), 'order' => 'ref', ))); if (isset($this->request->data['Upload']['region_id'])) { // Image selected? if ($this->request->data['Upload']['file']['name'] == '') { $this->Session->setFlash('Please, select an image to upload.'); $this->redirect($this->referer()); } // All required data is collected. // Prepare uploading file to the server and store in the db. // Check if folder exist to store the Image in. $this->Region->recursive = 0; $propertyid = ($this->request->data['Upload']['property_id']); $property = ($this->Property->findById($propertyid)); $propertyref = $property['Property']['ref']; $regionid = ($this->request->data['Upload']['region_id']); $regionname = ($this->Region->findById($regionid)); $cdest = $regionname['Country']['countryname']; // Set Folder -> Country $rdest = $regionname['Region']['regionname']; // Set Folder -> Regionname $destination = (ROOT.DS.WEBROOT_DIR.DS.'img'.DS.$cdest.DS.$rdest.DS); //debug($destination); //$destination = (App.imageBaseUrl.DS.$cdest.DS.$rdest.DS); //debug($destination); // Folder exist? $folder = new Folder($destination); $folderexist = $folder->cd($destination); // Returns False on failure. if ($folderexist == false ) { // Create new folder. $folder->create($destination); } // Create the Filename. $tmp_name = ($this->request->data['Upload']['file']['tmp_name']); $filename = ($this->request->data['Upload']['file']['name']); $fileprefix = $propertyref; // New filename. $filext = substr($filename, -4); // Keep file extension. // Count the files in the destination folder. $dir = new Folder($destination); // Destination folder. $files = $dir->find('$propertyref.*', true); // Creates array with filenames. $counter = count($files); // Count the files. if ($counter == 0){ // No such files $counter = $counter + 1; // First image. } $filemid = sprintf('%01d', $counter); // Add number to filename. $filename = ($fileprefix.$filemid.$filext); // Put the parts together. // Check if the file exist. if (file_exists($destination.$filename)) { // Yes, we need to increase the counter. while (file_exists($destination.$filename)) { $counter = $counter + 1; $filemid = sprintf('%01d', $counter); $filename = ($fileprefix.$filemid.$filext); //debug($filename); }} // Upload the file to the server/folder. move_uploaded_file($tmp_name, $destination . $filename); // Prepare for writing to the database. $filesize = ($this->request->data['Upload']['file']['size']); $createdt = date('Y-m-d H:i:s'); $description = ($this->request->data['Upload']['description']); if ($description == '') { // Is the Tag/Description empty? $description = $filename; // Yes, we use the filename. } // Create the Array with correct name and fields for the DB. $this->request->data['PropertyImage']['filename'] = $cdest.DS.$rdest.DS.$filename; $this->request->data['PropertyImage']['filesize'] = $filesize; $this->request->data['PropertyImage']['description'] = $description; $this->request->data['PropertyImage']['createdt'] = $createdt; $this->request->data['PropertyImage']['property_id'] = $propertyid; // Save to the database. $this->PropertyImage->save($this->request->data); $this->set('selectedRegionID', $this->request->data['Upload']['region_id']); $this->set('selectedPropertyID', $this->request->data['Upload']['property_id']); $this->Session->setFlash('Image is uploaded and stored in the database.'); // Done. } else { $selectedRegionID = false; $this->set('selectedRegionID', $selectedRegionID); } // Go back. } } ?>
Any help much appreciated.
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment