Eu fiz um component para isso:
(ta sem comentário...)
<?
class UploadComponent extends Object{
var $controller = true;
var $path = "";
var $maxSize;
var $allowedExtensions = array("jpg", "jpeg", "gif");
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;
$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 copyUploadedFile($source, $destination){
$pass = false;
if (is_uploaded_file($_FILES[$source]["tmp_name"])){
if ($_FILES[$source]["size"] < $this->maxSize){
if (count($this->allowedExtensions)==0){
// dont make
validation
$pass = true;
}else{
// make
validation
$pass = false;
foreach($this->allowedExtensions as $ext){
if
(eregi(".*".$ext."$",$_FILES[$source]["name"])){
$pass = true;
}
}
}
}
if ($pass){
// make upload
$ext = $this->getExt($_FILES[$source]
["name"]);
move_uploaded_file($_FILES[$source]["tmp_name"], $this->path.
$destination.".".$ext);
}else{
// dont make the upload
}
}
}
}
?>
On 16 ago, 12:53, hostdesigner <[EMAIL PROTECTED]> wrote:
> Como eu resgato o nome e nome temporário do arquivo no cake?
>
> Eu consigo resgatar o nome do arquivo assim,
>
> $this->params['form']['meu_campo']
>
> Só que desta forma aparentemente não tenho aceso ao handler para poder
> manipular o arquivo, somente o nome do arquivo está disponível.
>
> Alguém tem solução?
>
> Falopa!
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---