http://www.symfony-project.org/forum/index.php?t=msg&&th=6895#msg_29771
action.class.php
<?php class user_galleryActions extends sfActions {
public function executeIndex()
{
$this->forward('default', 'module');
}public function executeUpload() {
if ($this->getRequest()->getMethod() != sfRequest::POST) {
# listing, first time
return sfView::SUCCESS;
} else {
MemberPeer::uploadProfileGallery($this);
$this->redirect('user_gallery/list');
exit;
}
}public function executeSetcover() {
$c = new Criteria();
$c->add(GalleryPeer::IS_COVER, 1);
$c->add(GalleryPeer::USER_ID, $this->getUser()->getAttribute('member_id', '', 'member'));
$gallery = GalleryPeer::doSelectOne($c);
if ($gallery) {
# set picture to not cover if cover pic exist
$gallery->setIsCover(0);
$gallery->save();
}$gallery = GalleryPeer::retrieveByPK($this->getRequestParameter('id'));
$gallery->setIsCover(1);
$gallery->save(); $this->redirect('user_gallery/list');
exit;
}public function executeUnsetcover() {
$gallery = GalleryPeer::retrieveByPK($this->getRequestParameter('id'));
$gallery->setIsCover(0);
$gallery->save(); $this->redirect('user_gallery/list');
exit;
}public function executeSetprivate() {
$gallery = GalleryPeer::retrieveByPK($this->getRequestParameter('id'));
$gallery->setIsPrivate(1);
$gallery->save(); $this->redirect('user_gallery/list');
exit;
}public function executeSetpublic() {
$gallery = GalleryPeer::retrieveByPK($this->getRequestParameter('id'));
$gallery->setIsPrivate(0);
$gallery->save(); $this->redirect('user_gallery/list');
exit;
}public function executeUpdatetitle() {
$gallery = GalleryPeer::retrieveByPK($this->getRequestParameter('id'));
$gallery->setTitle($this->getRequestParameter('title['.$this->getRequestParameter('id').']'));
$gallery->save(); $this->redirect('user_gallery/list');
exit;
}public function executeDelete() {
$gallery = GalleryPeer::retrieveByPK($this->getRequestParameter('id'));# remove physical file
unlink(sfConfig::get('sf_upload_dir').'/user_gallery/'.$this->getUser()->getAttribute('member_id', '', 'member') . '/' . $gallery->getFilename() . $gallery->getExt());
# remove thumbnail
unlink(sfConfig::get('sf_upload_dir').'/user_gallery/'.$this->getUser()->getAttribute('member_id', '', 'member') . '/' . $gallery->getFilename() . '_tn1' . '.png');# remove thumbnail
unlink(sfConfig::get('sf_upload_dir').'/user_gallery/'.$this->getUser()->getAttribute('member_id', '', 'member') . '/' . $gallery->getFilename() . '_tn2' . '.png');# delete db record $gallery->delete();
$this->redirect('user_gallery/list');
exit;
}public function executeList() {
$c = new Criteria();
$c->add(GalleryPeer::USER_ID, $this->getUser()->getAttribute('member_id', '', 'member'));$this->galleries = GalleryPeer::doSelect($c); }
public function handleErrorUpload() { $this->forward('user_gallery', 'list');
#return sfView::SUCCESS;
}
}listSuccess.php
i m list gal <hr> [forloop out user gallery]<br> <table border=1> <?php $img_url = 'http://' . $_SERVER['HTTP_HOST'] . '/spotss/web/uploads/user_gallery/'; ?> <?php foreach($galleries as $gallery): ?>
<?php echo form_tag('user_gallery/updatetitle?id='.$gallery->getId()) ?> <?php echo input_hidden_tag('id', $gallery->getId()) ?> <tr> <td><img src='<?php echo $img_url . $gallery->getUserId() . '/' . $gallery->getFilename() . '_tn1.png' ?>'> </td> <td> <?php echo input_tag('title[' .$gallery->getId() . ']' , $gallery->getTitle()) ?></td> <td>
<?php if ($gallery->getIsCover()): ?>
<?php echo button_to('UnSet Cover', 'user_gallery/unsetcover?id=' . $gallery->getId()) ?><br>
<?php else: ?>
<?php echo button_to('Set Cover', 'user_gallery/setcover?id=' . $gallery->getId()) ?><br>
<?php endif; ?><?php if ($gallery->getIsPrivate()): ?>
<?php echo button_to('Set Public', 'user_gallery/setpublic?id=' . $gallery->getId()) ?><br>
<?php else: ?>
<?php echo button_to('Set Private', 'user_gallery/setprivate?id=' . $gallery->getId()) ?><br>
<?php endif; ?><?php echo submit_tag('Update Title') ?><br>
<?php echo button_to('Delete', 'user_gallery/delete?id=' . $gallery->getId()) ?><br> </td>
</tr>
</form>
<?php endforeach; ?>
</table>
<hr>
<?php use_helper('Object') ?>
<?php use_helper('Validation') ?><?php echo form_tag('user_gallery/upload', 'method=post multipart=true') ?> <hr> Title: <?php echo form_error('title') ?> <?php echo input_tag('title', '') ?> <br> Image :
<?php echo form_error('user_image') ?>
<?php echo input_file_tag('user_image') ?>
<br><?php echo submit_tag('upload') ?> </form>
upload.yml version 1
methods: post: [user_image]
names: user_image: required: true required_msg: Please upload an image file file: True sfFileValidator: mime_types: - 'image/jpeg' - 'image/jpg' - 'image/png' - 'image/x-png' - 'image/pjpeg' mime_types_error: Only PNG and JPEG images are allowed max_size: 512000 max_size_error: Max size is 512Kb
fillin: enabled: true # Enable the form repopulation
upload.yml version2
methods: post: [user_image]
names: user_image: required: true required_msg: Please upload an image file validators: imageFileValidator
imageFileValidator: class: sfFileValidator param: mime_types: - 'image/jpeg' - 'image/jpg' - 'image/png' - 'image/x-png' - 'image/pjpeg' mime_types_error: Only PNG and JPEG images are allowed max_size: 512000 max_size_error: Max size is 512Kb
fillin: enabled: true # Enable the form repopulation
If i m using upload.yml ver1, Empty Error can be checked, but for file checking failed, The require checking for user_image is applicable, but it will bypass checking 'file type'. It accept whatever file i uploaded, it bypass validation even i upload a .mp3 file and come to error page
[Exception] Could not load image stack trace
at () in SF_ROOT_DIR\lib\plugins\sfGDAdapter.class.php line 86 … 83.
at sfGDAdapter->loadFile(object('sfThumbnail'), '') in SF_ROOT_DIR\lib\plugins\sfThumbnail.class.php line 69 …
But if i m using upload.yml ver2 Empty error can be checked, and whatever file format i uploaded(even image format), it will block with the same message
Please upload an image file