Olá Galera, É o seguinte, tenho um sistema de upload que tá funcionando legal...envia o arquivo, renomeia, lista o diretório, exclui e visualiza os arquivos existentes. Porém quero algo mais e não como fazer...para renomear quero que seja feito com nomes prédefinidos. Deverá ser um combo com as opções dos nomes, depois de escolhido ele já grava o arquivo com o nome escolhido no combo... Abaixo segue o meu arquivo de upload até pra quem se interessar...n foi feito por mim mas é muito legal <?php ################## configurations #################### # header & title of this file $title = "PAINEL DE ATUALIZAÇÃO "; # individual file size limit - in bytes (102400 bytes = 100KB) $file_size_ind = "10239000"; # the upload store directory (chmod 777) $dir_store= "upload/"; # the images directory $dir_img= "www.freire.com.br/buscacp/upload/img/"; # the style-sheet file to use (located in the "img" directory, excluding .css) $style = "style-def"; # the file type extensions allowed to be uploaded $file_ext_allow = array("htm"); # option to display the file list # to enable/disable, enter '1' to ENABLE or '0' to DISABLE (without quotes) $file_list_allow = 1; # option to allow file deletion # to enable/disable, enter '1' to ENABLE or '0' to DISABLE (without quotes) $file_del_allow = 1; # option to password-protect this script [-part1] # to enable/disable, enter '1' to ENABLE or '0' to DISABLE (without quotes) $auth_ReqPass = 0; # option to password-protect this script [-part2] # if "$auth_ReqPass" is enabled you must set the username and password $auth_usern = "username"; $auth_passw = "password"; ################ end of configurations ############### # DO NOT ALTER OR EDIT BELOW THIS LINE UNLESS YOU ARE AN ADVANCED PHP PROGRAMMER ?> <? if (@phpversion() < '4.1.0') { $_FILE = $HTTP_POST_FILES; $_GET = $HTTP_GET_VARS; $_POST = $HTTP_POST_VARS; } clearstatcache(); error_reporting(E_ALL & ~E_NOTICE); $fum_vers = "1.3"; # do not edit this line, the script will not work!!! $fum_info_full = "PAINEL DE ATUALIZAÇÃO"; function authDo($auth_userToCheck, $auth_passToCheck) { global $auth_usern, $auth_passw; $auth_encodedPass = md5($auth_passw); if ($auth_userToCheck == $auth_usern && $auth_passToCheck == $auth_encodedPass) { $auth_check = TRUE; } else { $auth_check = FALSE; } return $auth_check; } if (isset($logout)) { setcookie ('fum_user', "",time()-3600); setcookie ('fum_pass', "",time()-3600); } if (isset($login)) { $auth_password_en = md5($auth_formPass); $auth_username_en = $auth_formUser; if (authDo($auth_username_en, $auth_password_en)) { setcookie ('fum_user', $auth_username_en,time()+3600); setcookie ('fum_pass', $auth_password_en,time()+3600); $auth_msg = "<b>Erro!</b> Cookies.<br><br>". $auth_msg . "Âàø ïàðîëü (MD5 encrypted) : $auth_password_en"; } else { $auth_msg = "<b>Arquivo alterado!</b>"; } } if (($_GET[act]=="dl")&&$_GET[file]) { if ($auth_ReqPass != 1 || ($auth_ReqPass == 1 && isset($fum_user) && !isset($logout))) { if ($auth_ReqPass != 1 || ($auth_ReqPass == 1 && authDo($fum_user, $fum_pass))) { $value_de=base64_decode($_GET[file]); $dl_full=$dir_store."/".$value_de; $dl_name=$value_de; if (!file_exists($dl_full)) { echo"O arquivo já existe no servidor.<br>»<a href=\"$_SERVER[PHP_SELF]\">Voltar</a>"; exit(); } @readfile($dl_full); exit(); } } } function getlast($toget) { $pos=strrpos($toget,"."); $lastext=substr($toget,$pos+1); return $lastext; } function replace($o) { $o=str_replace("/","",$o); $o=str_replace("\\","",$o); $o=str_replace(":","",$o); $o=str_replace("*","",$o); $o=str_replace("?","",$o); $o=str_replace("<","",$o); $o=str_replace(">","",$o); $o=str_replace("\"","",$o); $o=str_replace("|","",$o); return $o; } ?> <!-- <?=$fum_info_full?> --> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <script type="text/JavaScript"> <!-- function MM_openBrWindow(theURL,winName,features) { //v2.0 window.open(theURL,winName,features); } //--> </script> <head> <title><? echo ($title) ? ($title) : ("PAINEL DE ATUALIZAÇÃO DA FREIRE INFORMÁTICA - PREFEITURA DE ADUSTINA ANO 2007"); ?></title> <link rel="stylesheet" href="<?=$dir_img?>/<?=$style?>.css" type="text/css"> <? if ($auth_ReqPass == 1) { if (isset($login) || isset($logout)) { echo("<meta http-equiv='refresh' content='2;url=$_SERVER[PHP_SELF]'>"); } } ?> </head> <body bgcolor="#F7F7F7"> <br> <br> <table width="60%" height="320" align="center" class="borda"> <tr> <td width="49%" valign="top"><br> <center> <? if ($auth_ReqPass != 1 || ($auth_ReqPass == 1 && isset($fum_user) && !isset($logout))) { if ($auth_ReqPass != 1 || ($auth_ReqPass == 1 && authDo($fum_user, $fum_pass))) { ?> <table width="80%" cellspacing="0" cellpadding="0" border="0" class="table_auth"> <tr> <td><div align="center" onClick="MM_openBrWindow('../../index.php','','scrollbars=yes,width=650,height=600')"><font color="#808080" face="Verdana" size="1"><b>PAINEL DE ATUALIZAÇÃO <br> </b></font> <span class="texto2">[Só é permitido o envio de arquivos HTML!]</span><br> <span class="título"><span class="style3"><a href="#">[ </a></span></span><a href="#"><span class="texto2">Clique aqui</span><span class="título"><span class="style3"> e verifique aqui os arquivos existentes e pendentes ]</span></span></a><span class="título"><span class="style3"> </span></span></div></td> </tr> </table> <br> <? if (!eregi("777",decoct(fileperms($dir_store)))) { echo"<br><br><b><h4><font color=\"FF0000\">ERRO: Você deve dar permissão de escrita para o diretório \"$dir_store\" , CHMOD 0777 (xrw-xrw-xrw)!</h4></font></b><br>»<a href=\"$_SERVER[PHP_SELF]\">Voltar</a>"; } else { if (!$_FILES[fileupload]) { ?> <table width="80%" cellspacing="0" cellpadding="0" border="0" class="texto" style="padding-top:5px;padding-left=5px;padding-bottom:5px;padding-right:5px"> <form method="post" enctype="multipart/form-data"> <tr> <td width="20%"> </td> <td width="18%" valign="top">Arquivo:</td> <td width="64%" height="25" valign="top"><input type="file" name="fileupload" class="texto2" size="30"></td> </tr> <tr> <td nowrap> </td> <td valign="top" nowrap>Renomear para:</td> <td height="35" valign="top"><input type="text" name="rename" class="texto2" size="46"> <br> Ex: rreoanexoi01<br></td> </tr> <tr> <td nowrap> </td> <td valign="top" nowrap>Tamanho máximo:</td> <td valign="top"><b> <? if ($file_size_ind >= 1048576) { $file_size_ind_rnd = round(($file_size_ind/10240000),3) . " MB"; } elseif ($file_size_ind >= 1024) { $file_size_ind_rnd = round(($file_size_ind/1024),2) . " KB"; } elseif ($file_size_ind >= 0) { $file_size_ind_rnd = $file_size_ind . " bytes"; } else { $file_size_ind_rnd = "0 bytes"; } echo "$file_size_ind_rnd"; ?> </b> </td> </tr> <tr> <td height="15" colspan="3"> </td> </tr> <tr> <td colspan="3" align="center"><input name="submit2" type="submit" class="texto2" value="Enviar"> <input name="reset" type="reset" class="texto2" value="Cancelar"></td> </tr> </form> </table> <? //Pegando o nome echo $name = $f_name[$i]; ?> <? if ((!$_GET[act]||!$_GET[file])&&$_GET[act]!="delall") { $opendir = @opendir($dir_store); while ($readdir = @readdir($opendir)) { if ($readdir<>"." && $readdir<>".." && $readdir != "index3.php") { $filearr[] = $readdir; } $sort=array(); for($i=1;$i<=count($filearr);$i++) { $key = sizeof($filearr)-$i; $file = $filearr[$key]; $sort[$i]=$file; } asort($sort); } ?> <br> <table width="80%" cellspacing="0" cellpadding="0" border="0" class="texto" style="padding-left:5px"> <tr> <td><b>Arquivos atuais:</b> <? if ($file_del_allow != 1 && $auth_ReqPass != 1) { echo"<i>none</i>"; } if ($file_del_allow == 1 && $file_list_allow == 1 && (count($filearr) >= 1)) { echo"<a href=\"java script:;\" onClick=\"cf=confirm('Todo conteúdo será apagado. Você confirma?');if (cf)window.location='?act=delall'; return false;\" style=\"font-size: 10px;\">Apagar todos os arquivos;</a>"; } if ($auth_ReqPass == 1) { echo" <a href=\"$_SERVER[PHP_SELF]?logout=1\" style=\"font-size: 9px;\"><log-out><a>"; } ?> </td> </tr> </table> <br> <? if ($file_list_allow == 1 && (count($filearr) >= 1)) { ?> <table width="80%" cellspacing="0" cellpadding="0" border="0" class="texto" style="padding-left:6px"> <tr bgcolor="#DBDBDB"> <td width="46%" align="left" class="texto2">NOME</td> <td width="12%" align="center" class="texto2">TIPO</td> <td width="12%" align="center" class="texto2">TAMANHO</td> <td width="30%" align="center" class="texto2">ACÕES</td> </tr> <? for($i=1;$i<=count($sort);$i++) { list($key,$value)=each($sort); if ($value) { $value_en = base64_encode($value); $value_view=$value; if (strlen($value) >= 48) { $value_view = substr($value_view, 0, 45) . '...'; } ?> <tr> <td width="30%"><?="<a href=\"?act=view&file=$value_en\">$value_view</a>"?></td> <td align="center" width="5%"><? echo strtoupper(getlast($value)); ?></td> <td align="center" width="5%"><? $value_full = $dir_store."/".$value; $file_size = filesize($value_full); if ($file_size >= 1048576) { $show_filesize = number_format(($file_size / 1048576),2) . " MB"; } elseif ($file_size >= 1024) { $show_filesize = number_format(($file_size / 1024),2) . " KB"; } elseif ($file_size >= 0) { $show_filesize = $file_size . " áàéò"; } else { $show_filesize = "0 áàéò"; } echo "$show_filesize"; ?></td> <td align="center" width="5%"><?="<a title=\"Ver\" href=\"?act=view&file=$value_en\">Ver</a>"?> | <? if ($file_del_allow == 1) { echo"<a title=\"Baixar\" href=\"?act=dl&file=$value_en\">Baixar</a>"; } else { echo"<a title=\"Baixar\" href=\"?act=dl&file=$value_en\">Baixar</a>"; } if ($file_del_allow == 1) { echo" | <a title=\"Apagar\" href=\"java script:;\" onClick=\"cf=confirm('O arquivo será apagado. Você confirma?');if (cf)window.location='?act=del&file=$value_en'; return false;\">Apagar</a>"; } else { echo" "; } ?> </td> </tr> <? } else { echo"<br>"; } } ?> </table> </center> <? } } elseif (($_GET[act]=="view")&&$_GET[file]) { $value_de = base64_decode($_GET[file]); echo"<script language=\"javascript\">\nViewPopup = window.open(\"$dir_store/$value_de\", \"fum_viewfile\", \"toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,location=no,width=640,height=480\")\nViewPopup.document.bgColor=\"#F7F7F7\"\nViewPopup.document.close()\n</script>"; echo"<br><img src=\"$dir_img/info.gif\" width=\"15\" height=\"15\"> <b><font size=\"2\">Ver</font></b><br>»<a href=\"$_SERVER[PHP_SELF]\">Voltar</a><br><br><br>Seu browser deve permitir javascript e PopUp."; } elseif (($_GET[act]=="del")&&$_GET[file]) { $value_de = base64_decode($_GET[file]); @unlink($dir_store."/$value_de"); echo"<br><img src=\"$dir_img/info.gif\" width=\"15\" height=\"15\"> <b><font size=\"2\">Arquivo apagado</font></b><br>»<a href=\"$_SERVER[PHP_SELF]\">Continuar</a>"; } if ($_GET[act]=="delall") { $handle = opendir($dir_store); while($file=readdir($handle)) if (($file != ".")&&($file != "..")) @unlink($dir_store."/".$file); closedir($handle); echo"<br><img src=\"$dir_img/info.gif\" width=\"15\" height=\"15\"> <b><font size=\"2\">Arquivos apagados!</font></b><br>»<a href=\"$_SERVER[PHP_SELF]\">Continuar</a>"; } } else { echo"<br><br>"; $uploadpath=$dir_store."/"; $source=$_FILES[fileupload][tmp_name]; $fileupload_name=$_FILES[fileupload][name]; $weight=$_FILES[fileupload][size]; for($i=0;$i<count($file_ext_allow);$i++) { if (getlast($fileupload_name)!=$file_ext_allow[$i]) $test.="~~"; } $exp=explode("~~",$test); if (count($exp)==(count($file_ext_allow)+1)) { echo"<br><img src=\"$dir_img/error.gif\" width=\"15\" height=\"15\"> <b><font size=\"2\">Erro: (".getlast($fileupload_name).")</font>, não foi possível efetuar o upload.</b><br>»<a href=\"$_SERVER[PHP_SELF]\">Continuar</a>"; } else { if ($weight>$file_size_ind) { echo"<br><img src=\"$dir_img/error.gif\" width=\"15\" height=\"15\"> <b><font size=\"2\">Îøèáêà: ïîæàëóéñòà ïîëó÷èòå ðàçìåð ôàéëà ìåíüøå ÷åì ".$file_size_ind." BYTES (".round(($file_size_ind/1024),2)." KB)</font></b><br>»<a href=\"$_SERVER[PHP_SELF]\">Voltar</a>"; } else { foreach($_FILES[fileupload] as $key=>$value) { echo"<font color=\"#3399FF\">$key</font> : $value <br>"; } echo "<br>"; $dest = ''; if (($source != 'none') && ($source != '' )) { $dest=$uploadpath.$fileupload_name; if ($dest != '') { if (file_exists($uploadpath.$fileupload_name)) { echo"<br><img src=\"$dir_img/error.gif\" width=\"15\" height=\"15\"> <b><font size=\"2\">ERRO: O arquivo já existe.</font></b><br>»<a href=\"$_SERVER[PHP_SELF]\">Voltar</a>"; } else { if (copy($source,$dest)) { if ($_POST[rename]) { $_POST[rename]=replace($_POST[rename]); $exfile=explode(".",$fileupload_name); if (@rename("$dir_store/$fileupload_name","$dir_store/$_POST[rename].".getlast($fileupload_name))) { echo"<br><img src=\"$dir_img/info.gif\" width=\"15\" height=\"15\"> <b><font size=\"2\">O arquivo foi enviado e renomeado para $_POST[rename].".getlast($fileupload_name)."!</font></b></font><br>"; } } echo"<br><img src=\"$dir_img/info.gif\" width=\"15\" height=\"15\"> <b><font size=\"2\"></font></b><br>»<a href=\"$_SERVER[PHP_SELF]\">Voltar</a>"; } else { echo"<br><img src=\"$dir_img/error.gif\" width=\"15\" height=\"15\"> <b><font size=\"2\">Sem permissão na pasta</font></b><br>»<a href=\"$_SERVER[PHP_SELF]\">íàçàä</a>"; } } } } } } } } #/# end of main script, start authentication code IF user not logged in IF $auth_ReqPass is enabled } else { echo("<p><img src=\"$dir_img/error.gif\" width=\"15\" height=\"15\"></p>" . "<p><a href='$_SERVER[PHP_SELF]?logout=1'><a></p>"); } } else { if (!isset($login) || isset($relogin)) { ?> <font size="3"><b><i><? echo ($title) ? ($title) : ("PAINEL DE ATUALIZAÇÃO DA FREIRE INFORMÁTICA - PREFEITURA DE ADUSTINA ANO 2007"); ?></i> - </b></font></td> </tr></table> </center> <? } elseif (isset($login)) { echo("<p>$auth_msg</p>" . "<p>!</p>"); } } ?>[/codebox]