Túlio.
Dei uma mudadinha no seu componente para usar... Peço sua aprovação.
Mas antes. Galera... Não use o cake (HTML helper) para criar o campo de
formulário nesse caso. Use o bom e velho HTML:
CERTO
<input type="file" id="imagem" name="imagem"/>
ERRADO (gerado pelo cake)
<input type="file" id="MaterialImagem" name="data[Material][imagem]"/>
Abraços
Voltando. Túlio, o componente modificado:
---[corte daqui para baixo, estrague seu monitor ]--8<---
<?php
class UploadComponent extends Object{
var $controller = true;
var $path = "";
var $maxSize;
var $allowedExtensions = array("jpg", "jpeg", "gif", "png");
function startup(&$controller){
$this->path = APP . WEBROOT_DIR . DS;
$this->maxSize = 2*1024*1024; // 2MB
}
function setPath($p){
if ($p!=NULL){
$this->path = $this->path . $p . DS;
$this->path = eregi_replace("/", DS, $this->path);
$this->path = eregi_replace("\\\\", DS, $this->path);
return true;
}
}
function setMaxFileSize($size){
$this->maxSize = $size;
}
function addAllowedExt($ext){
if (is_array($ext)){
$this->allowedExtensions =
array_merge($this->allowedExtensions, $ext);
}else{
array_push($this->allowedExtensions, $ext);
}
}
function getExt($file){
$p = explode(".", $file);
return $p[count($p)-1];
}
function verifyUpload($file){
$passed = false;
if(is_uploaded_file($file["tmp_name"])){
$ext = $this->getExt($file["name"]);
if((count($this->allowedExtensions) == 0) ||
(in_array($ext, $this->allowedExtensions))){
$passed = true;
}
}
return $passed;
}
function copyUploadedFile($source, $destination){
if($this->verifyUpload($_FILES[$source])){
move_uploaded_file(
$_FILES[$source]["tmp_name"],
$this->path . $destination . DS . $_FILES[$source]["name"]);
}
}
}
?>
--~--~---------~--~----~------------~-------~--~----~
Recebeu esta mensagem porque está inscrito em Grupo "Cake PHP Português" do
Grupos Google.
Para enviar mensagens para este grupo, envie um email para
[email protected]
Para anular a inscrição neste grupo, envie um email para [EMAIL PROTECTED]
Para mais opções, visite este grupo em
http://groups.google.com/group/cake-php-pt?hl=pt-PT
-~----------~----~----~----~------~----~------~--~---