Ciao a tutti, avrei un problema, in quanto quando un file viene uploadato sul mio sito ed ha lo stesso nome di un altro esso viene sovrascritto, così ho pensato di mettere un random code, faccio un esempio: il file che viene uploadato si chiama "ciao.txt" e con il codice random lo rinnomina in ghsl.txt
Il problema è che sò poco e niente di PHP e quindi, se possibile, vorrei una mano.
Codice PHP:
<script type="text/javascript" src="http://www.era404.com/js/swfobject.js"></script> <link href="_css/era404.css" rel="stylesheet" type="text/css" /> <script src="_js/swfobject.js" type="text/javascript"></script> <script type="text/javascript"> function formValidator() { var up = document.getElementById("flash_uploader"); var fb = document.getElementById('flash_block'); var upload_button = document.theForm.action_upload; var upload_url = "upload.php"; up.SetVariable("upload_to", upload_url); up.SetVariable("upload_dir", "<?php echo $dir ?>"); up.SetVariable("ul", "100"); upload_button.disabled='true'; return false; } function upload_complete(name,size,type,ft,dir,a) { window.location="index.php?name="+name+"&size="+size+"&type="+type+"&exts="+ft+"&dir="+dir+"&a="+a; } function fileProps(name,size,type,cdate,mdate,dir) { var props = document.getElementById('props'); props.innerHTML = "<div class='sucErr'><div class='tableHeader' style='width: 400px; height: 20px; padding-top: 5px;'>File selezionato:</div>
<table border='0' cellspacing='0' cellpadding='0' style='margin:10px;'><tr><td width='100'>[b]NOME:[/b]</td><td> "+dir+"/"+name+"</td></tr><tr><td>[b]GRANDEZZA:[/b]</td><td> "+size+"</td></tr><tr><td>[b]ESTENSIONE:[/b]</td><td> "+type+"</td></tr><tr><td>[b]CREATO:[/b]</td><td> "+cdate+"</td></tr><tr><td>[b]MODIFICATO:[/b]</td><td> "+mdate+"</td></tr></table></div>"; props.style.display = "block"; } function thumbs() { var mdir = '<?=(@$dir?"?dir=$dir":"")?>'; var thumbs = document.getElementById('thm'); if(thumbs.checked == true) { window.location = "index.php"+mdir+"&thm=1"; } else { window.location = "index.php"+mdir; } } </script> </head> <a name="top"></a> <body> <center>
<div id='props' style='display:none;font: 8pt Verdana, Georgia, Sans-serif !important;width:360px;margin:10px;padding:10px;'></div> <form method="post" enctype="multipart/form-data" name="theForm" id="theForm" onSubmit="return formValidator();"> <? if(@!empty($_GET['name'])) { $_GET['name'] = cleanFileName($_GET['name']); echo "<div id='props' style='display:block;font: 8pt Verdana, Georgia, Sans-serif !important;width:360px;margin:10px;padding:10px;'>"; if(file_exists(getcwd().'/'.$dir.'/'.$_GET['name'])) { echo "<div class='sucErr'><div class='tableHeader' style='width: 400px; height: 20px; padding-top: 5px;'>Uploadato!</div>
"; echo "<span class='standardCopy'>[i]{$_GET['name']}[/i]
File uploadato con successo!</span>
"; } else { echo "<div class='sucErr'><div class='tableHeader' style='width: 400px; height: 20px; padding-top: 5px;'>Errore:</div>
"; $_GET['exts'] = explode(",",$_GET['exts']); $_GET['allowed'] = (in_array(LTRIM(strtolower($_GET['type']),"."),$_GET['exts']) ? "yes" : ($_GET['a'] == true ? "yes" : "no")); $maxsize = return_bytes(ini_get('post_max_size')); echo "<span class='standardCopy'>Il file non è stato uploadato.</span>
"; if($_GET['allowed'] == "no") { echo "<span class='standardCopy'>[b]Filetype (".$_GET['type'].") not permitted.[/b]</span>
"; } else { echo ($_GET['size'] > $maxsize ? "<span class='standardCopy'>[b]Filesize ({$_GET['size']}) is larger than permitted by this host ($maxsize).[/b]</span>
" : "
"); } echo "<span class='boldCopy'>FILE: </span><span class='standardCopy'>".$_GET['name']. "</span>
"; echo "<span class='boldCopy'>TIPO: </span><span class='standardCopy'>".$_GET['type']. "</span>
"; echo "<span class='boldCopy'>GRANDEZZA: </span><span class='standardCopy'>".$_GET['size']. "</span>
"; echo "<span class='boldCopy'>ALLOWED: </span><span class='standardCopy'>".$_GET['allowed']. "</span>
"; } echo "</div></div>"; $_GET = array(); } session_destroy(); ?> <div id="flash_block" style="display: visible;"> <div id="flashcontent"></div> </div> <script type="text/javascript"> var fo = new SWFObject("uploader.swf?ul=100", "flash_uploader", "435", "70", 8, "#FFFFFF", true); fo.addParam("allowScriptAccess", "sameDomain"); fo.addParam("quality", "high"); fo.addParam("scale", "noscale"); fo.addVariable("to", "upload.php"); fo.addVariable("upload_dir", "<?=$dir?>"); fo.addVariable("limit", "100"); fo.addVariable("types", "video|text|pdf|audio|archive|office|image|all"); fo.write("flashcontent"); </script> <!--<input name="action_upload" type="submit" value="Upload Video">
--> </form> <div style='display:block;font: 8pt Verdana, Georgia, Sans-serif !important;margin:10px;padding:10px; height: 565px; overflow: auto;'> <table width='95%' border='0' cellpadding="5" cellspacing="0" style="margin-left:10px;"> <tr> <td colspan='5'><? echo $acct; ?></td> </tr> <tr> <td class="tableHeader" width="15"></td> <td class="tableHeader">Nome File</td> <td class="tableHeader">Data di Upload</td> <td class="tableHeader">Grandezza</td> <td class="tableHeader">Descrizione</td> </tr> <?php $imgtypes = array("jpg"=>1,"jpeg"=>1,"gif"=>2,"png"=>3); $showthumbs = (@isset($_GET['thm']) ? 1 : 0); if(!file_exists(getcwd()."/$dir/.s/")) @mkdir(getcwd()."/$dir/.s/",0777); if(file_exists("$dir/")) { if ($handle = opendir("$dir/")) { $count = 0; while (false !== ($file = readdir($handle))) { if($file != "." && $file != ".." && $file != ".s") { $count++; if(!file_exists(getcwd()."/$dir/.s/$file") && array_key_exists(strtolower(substr($file,-3)),$imgtypes)) { $srcf = getcwd()."/$dir/$file"; $dstf = getcwd()."/$dir/.s/$file"; $type = $imgtypes[strtolower(substr($file,-3))]; mcSaveImages(120,90,$srcf,$dstf,15,$type); } echo "<tr bgcolor='".($count%2?"#FFFFFF":"#EFEFEF")."'> <td valign='top'>$count.</td> <td valign='top'>[url='$dir/$file']$file[/url]</td> <td valign='top'>".date("m/d/Y h:i:s A",filectime(getcwd()."/$dir/$file"))."</td> <td valign='top'>".niceSize(filesize(getcwd()."/$dir/$file"))."</td>"; if($showthumbs) { if(array_key_exists(strtolower(substr($file,-3)),$imgtypes)) { echo "<td>[url='$dir/$file'][img]$dir/.s/$file[/img][/url]
"; } else { echo "<td align='left'>"; } $details = $id3->analyze(getcwd()."/$dir/$file"); echo "<font size='-3'>"; if(@array_key_exists("video",$details)) { echo "[b]DETTAGLI IMMAGINE:[/b]<hr width='200' align='left' style='border:1px solid #000;'></hr><ul>"; foreach($details['video'] as $k=>$v) { echo "[b]$k:[/b] $v
"; } if(@$details['playtime_string']) { echo "[b]Playtime:[/b] {$details['playtime_string']}
"; }echo "[/list]"; } if(@array_key_exists("audio",$details)) { echo "[b]DETTAGLI AUDIO:[/b]<hr width='200' align='left' style='border:1px solid #000;'></hr><ul>"; foreach($details['audio'] as $k=>$v) { echo "[b]$k:[/b] $v
"; } echo "[/list]"; } echo "</td>"; } else { echo "<td></td>"; } echo "</tr>"; } } closedir($handle); } } ?> </table><div style="clear:both;"></div>
</div> <table><tr> <td><input type='checkbox' name='thm' id="thm" onclick="javascript:thumbs();" <? echo($showthumbs ? "CHECKED" : ""); ?>></td> <td colspan="3">
Clicca qui per i dettagli!</p></td> </tr> </table> <?php function mcSaveImages($forcedwidth, $forcedheight, $sourcefile, $destfile, $imgcomp, $type) { //$type = 1: jpeg | $type = 2: gif | $type = 3: png $g_imgcomp=100-$imgcomp; $g_srcfile=$sourcefile; $g_dstfile=$destfile; $g_fw=$forcedwidth; $g_fh=$forcedheight; if(file_exists($g_srcfile)) { $g_is=getimagesize($g_srcfile); if(abs($g_is[0]-$g_fw)>=abs($g_is[1]-$g_fh)) { $g_iw=$g_fw; $g_ih=abs($g_fw/$g_is[0])*$g_is[1]; } else { $g_ih=$g_fh; $g_iw=abs($g_ih/$g_is[1])*$g_is[0]; } if($type == 1) $img_src=imagecreatefromjpeg($g_srcfile); if($type == 2) $img_src=imagecreatefromgif($g_srcfile); if($type == 3) $img_src=imagecreatefrompng($g_srcfile); $img_dst=imagecreatetruecolor($g_iw,$g_ih); imagecopyresampled($img_dst, $img_src, 0, 0, 0, 0, $g_iw, $g_ih, $g_is[0], $g_is[1]); if($type == 1) imagejpeg($img_dst, $g_dstfile, $g_imgcomp); if($type == 2) imagegif($img_dst, $g_dstfile, $g_imgcomp); if($type == 3) imagepng($img_dst, $g_dstfile, $g_imgcomp); imagedestroy($img_dst); return true; } else return false; } function niceSize($size) { $sidestep = 1024.0; static $sizeUnits = Array(); if (count($sizeUnits)==0) { $sizeUnits[] = ""."B"; $sizeUnits[] = "KB"; $sizeUnits[] = "MB"; $sizeUnits[] = "GB"; $sizeUnits[] = "TB"; } if ($size==="") return ""; $unitIndex = 0; while ($size>$sidestep) { $size = $size / $sidestep; $unitIndex++; } if ($unitIndex==0) { return number_format($size, 0)."".$sizeUnits[$unitIndex]; } else { return number_format($size, 1, ".", ",")."".$sizeUnits[$unitIndex]; } } function return_bytes($val) { $val = trim($val); $last = strtolower($val{strlen($val)-1}); switch($last) { // The 'G' modifier is available since PHP 5.1.0 case 'g': $val *= 1024; case 'm': $val *= 1024; case 'k': $val *= 1024; } return $val; } function cleanFileName($str) { $cleaner = array(); $cleaner[] = array('expression'=>"/[àáäãâª]/",'replace'=>"a"); $cleaner[] = array('expression'=>"/[èéêë]/",'replace'=>"e"); $cleaner[] = array('expression'=>"/[ìíîï]/",'replace'=>"i"); $cleaner[] = array('expression'=>"/[òóõôö]/",'replace'=>"o"); $cleaner[] = array('expression'=>"/[ùúûü]/",'replace'=>"u"); $cleaner[] = array('expression'=>"/[ñ]/",'replace'=>"n"); $cleaner[] = array('expression'=>"/[ç]/",'replace'=>"c"); $cleaner[] = array('expression'=>"/[ß]/",'replace'=>"ss"); $ext_point = strpos($str,"."); if ($ext_point===false) return false; $ext = substr($str,$ext_point,strlen($str)); $str = substr($str,0,$ext_point); foreach($cleaner as $cv) { $str = preg_replace($cv["expression"],$cv["replace"],$str); } return str_replace(" ","_",$str).$ext; } ?> </center> </body> </html>