Ciao a tutti
sto usando un semplice script per l'upload di un file e che me lo rinomina utomaticamente.
il form è composto da:
CITTA
NOME
FILE DA UPLODARE
Quando uppo il file voglio che me lo rinomini come CITTA_NOME.ESTENSIONE
ecco
Codice PHP:
function change ($stringa){
$stringa = ereg_replace(" ","_",$stringa);
$stringa = str_replace("\"","",$stringa);
$stringa = ereg_replace("\'","",$stringa);
return $stringa;
}
$new_citta = change($_POST['citta']);
$new_nome = change($_POST['nome']);
$sub_nome=substr("$new_nome",0,15);
if($_FILES['foto']['name']){
//ESTENSIONE
$trova_punto = explode(".", $_FILES['foto']['name']);
$estensione = $trova_punto[count($trova_punto) - 1];
$estensione = strtolower($estensione);
//NUOVO NOME
$new_name = "$new_citta"."_"."$sub_nome.$estensione";
//COPIO IL FILE
copy("$foto", "foto/".$new_name) or die("NON RIESCO AD INSERIRE LA MINIATURA");
//SQL PER DATABASE
$upfoto="foto='$new_name',";
@unlink("foto/$vecchia_foto");
}
perchè sul database il nome me lo scrive correttamente, mentre il file uppato se contiene apici o doppi apici mi ci mette la slash?
ecco l'esempio
Calvi_dellUmbria_FORTEZZA.eps (NOME SUL DB CORRETTO)
Calvi_dell\Umbria_FORTEZZA.eps (FILE UPPATO CON NOME SBAGLIATO)