/** * Returns array('success'=>true) or array('error'=>'error message') */ function handleUpload($uploadDirectory, $replaceOldFile = FALSE) { if (!is_writable($uploadDirectory)) { return array('error' => CocoWidget::t("Server error. Upload directory isn't writable.")); } if (!$this->file) { return array('error' => CocoWidget::t('No files were uploaded.')); } $size = $this->file->getSize(); if ($size == 0) { return array('error' => CocoWidget::t('El archivo esta vacio :(')); } if ($size > $this->sizeLimit) { return array('error' => CocoWidget::t('El archvivo es muy pesado :(')); } $pathinfo = pathinfo($this->file->getName()); $filename = $pathinfo['filename']; $filename = str_replace(' ', '', $filename); //$filename = md5(uniqid()); $ext = $pathinfo['extension']; if ($this->allowedExtensions && !in_array(strtolower($ext), $this->allowedExtensions)) { $these = implode(', ', $this->allowedExtensions); return array('error' => CocoWidget::t('Solo se permiten archivos .') . $these . '.'); } if (!$replaceOldFile) { /// don't overwrite previous files that were uploaded while (file_exists($uploadDirectory . $filename . '.' . $ext)) { $filename .= rand(10, 99); } } $fullpath = $uploadDirectory . $filename . '.' . $ext; if ($this->file->save($fullpath)) { return array('success' => true, 'filename' => $filename, 'size' => $size, 'ext' => $ext, 'path' => $uploadDirectory, 'fullpath' => $fullpath); } else { return array('error' => CocoWidget::t('No se ha podido subir el archvivo al servidor. Cuentele a los informáticos u_u')); } }
/** * this action invokes the appropiated handler referenced by a 'classname' url attribute. * the specified classname must implements: EYuiActionRunnable.php */ public function run() { //Yii::log('ACTION CALLED','info'); $inst = new CocoWidget(); $inst->runAction($_GET['action'], $_GET['data']); }
/** * Returns array('success'=>true) or array('error'=>'error message') */ function handleUpload($uploadDirectory, $nombrealti = 'perro', $replaceOldFile = FALSE) { if (!is_writable($uploadDirectory)) { return array('error' => CocoWidget::t("Server error. Upload directory isn't writable.")); } if (!$this->file) { return array('error' => CocoWidget::t('No files were uploaded.')); } $size = $this->file->getSize(); if ($size == 0) { return array('error' => CocoWidget::t('File is empty')); } if ($size > $this->sizeLimit) { return array('error' => CocoWidget::t('File is too large')); } $pathinfo = pathinfo($this->file->getName()); //$filename = $pathinfo['filename']; // if ($nombrealt===null) { // $filename = $pathinfo['filename']; } else { $filename = $nombrealti; $filename = gettype($nombrealti) . '.'; // } // $filename = $pathinfo['filename']; // $filename = md5(uniqid()); $filename = $pathinfo['filename']; $ext = $pathinfo['extension']; if ($this->allowedExtensions && !in_array(strtolower($ext), $this->allowedExtensions)) { $these = implode(', ', $this->allowedExtensions); return array('error' => CocoWidget::t('File has an invalid extension, it should be one of ') . $these . '.'); } if (!$replaceOldFile) { /// don't overwrite previous files that were uploaded while (file_exists($uploadDirectory . $filename . '.' . $ext)) { $filename .= rand(10, 99); } } $fullpath = $uploadDirectory . $filename . '.' . $ext; if ($this->file->save($fullpath)) { return array('success' => true, 'filename' => $filename, 'size' => $size, 'ext' => $ext, 'path' => $uploadDirectory, 'fullpath' => $fullpath); } else { return array('error' => CocoWidget::t('Could not save uploaded file. The upload was cancelled, or server error encountered')); } }