Eu usava ele no PHP4 e sempre funcionou, mais agora mudei para o PHP5 e n faz mais isso poderia me da uma ajuda..
O código
[codebox]<?
class UpLoadAndChangeTheName {
var $Archive;
var $Diretorio = '../imagem/';//Defina o diretório das imagens
var $Erro = array();
var $NomeGerado;
function FormFile(){
echo '<form method="post" action="'.$PHP_SELF.'" enctype="multipart/form-data"><br>
<table width="60%" border="0" align="center">
<tr align="center">
<td><strong>Arquivo - </strong></td>
<td><input type="file" name="foto" size="40" id="but"/></td>
<td><input type="submit" name="submit" value="Enviar!" id="but"/></td>
</tr>
</table>
</form>
';
} function CheckAction(){
if (empty($_POST['submit']))
{ $this->FormFile(); }else{ $this->Archive = $_FILES['foto']; $this->UpLoadFile(); } } function UpLoadFile(){ $NomeDoArquivo = $this->Archive['name']; $ArquivoTemporario = $this->Archive['tmp_name']; $Tipo = $this->Archive['type']; if(ereg("(image)", $Tipo)){ move_uploaded_file($ArquivoTemporario, $this->Diretorio.$NomeDoArquivo); $this->RenameFile(); }else{ $this->Erro['AI'] .= 'Arquivo inválido!'; $this->Erro['AI'] .= '<strong> ['.$this->Archive['type'].']</strong><br />'; $this->Erro['AI'] .= 'Este sistema aceita apenas arquivos com MIME contendo \'image\''; } } function RenameFile(){ $NovoNome = md5(mktime()); $NomeDoArquivo = $this->Archive['name']; $Separa = explode('.', $NomeDoArquivo); $NewName = $NovoNome.'.'.$Separa[1]; $FileSize = round($this->Archive['size']/1024, 1); $Renomeia = rename($this->Diretorio.$NomeDoArquivo, $this->Diretorio.$NewName); if($Renomeia){ echo '<div align="left">O Arquivo <strong>'.$NomeDoArquivo.'</strong> foi enviado e renomeado para <strong><a href="'.$this->Diretorio.$NewName.'">'.$NewName.'</a></strong><br/><br/> <em>Informações do Arquivo...</em><br /> <strong>Tamanho:</strong> '.$FileSize.' Kb. </div>'; }else{ $this->Erro[] = 'Erro ao renomear Arquivo!'; } } function ShowErrors(){ foreach($this->Erro as $Erro){ echo '<strong>Houve um erro:</strong> '.$Erro; } }}$CallClass = new UpLoadAndChangeTheName;$CallClass->CheckAction();$CallClass->ShowErrors();?>[/codebox]
Edição feita por: Paulo André, 05/10/2007, 11:28.
Utilize a tag [CODEBOX] para códigos longos