Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $username = "root";
- $password = "77applebed1250";
- $hostname = "localhost";
- //connection to the database
- $dbhandle = mysql_connect($hostname, $username, $password)
- or die("Unable to connect to server MySQL");
- echo "Connected to MySQL<br>";
- //select a database to work with
- $selected = mysql_select_db("forum2",$dbhandle)
- or die("Could not select db forum2");
- //execute the SQL query and return records
- $result = mysql_query("SELECT dw.id as id,sec.evento as evento,dw.file as file FROM mkp_download as dw,mkp_download_sections as sec WHERE (sec.id=dw.idcategoria)");
- //echo "<script language='JavaScript'>
- //newwindow=window.open('','risultato','height=500,width=500');
- //</script>";
- //fetch tha data from the database
- // Open a known directory, and proceed to read its contents
- $dir = "/var/www/virtual/unibosca.com/htdocs/public/mkportal/modules/downloads/file/";
- $dir2 = "/var/www/virtual/unibosca.com/htdocs/public/mkportal/modules/downloads/";
- if (is_dir($dir)) {
- if ($dh = opendir($dir)) {
- while (($file = readdir($dh)) !== false) {
- $name = $file;
- while ($row= mysql_fetch_array($result))a--
- {
- //$basefilename = preg_replace("/(.*)\.([^.]+)$/","\\1", $file);
- $basefilename = pathinfo($file, PATHINFO_FILENAME);
- //$filename = preg_replace("/(.*)\.([^.]+)$/","\\1", $row['file']);
- $filename = pathinfo($row['file'], PATHINFO_FILENAME);
- $pattern = "/".preg_quote($filename)."/";
- //echo $pattern.",".$filename."<br/>\n";
- echo $name;
- if (preg_match($pattern,$basefilename))
- {
- // salva_file($file,$row['file'],$row['evento']);
- $match = true;
- }
- if( $match ) continue;
- }
- }
- closedir($dh);
- }
- }
- function salva_file($originale,$nuovo,$categoria)
- {
- if (!is_dir($dir2.'/riorganizzato/'.$categoria)) mkdir ($dir2.'/riorganizzato/'.$categoria,0777,true);
- copy($dir.'/'.$originale,$dir2.'/riorganizzato/'.$categoria.'/'.$nuovo);
- echo $originale." copiano in /".$categoria."/".$nuovo;
- return true;
- }
- //close the connection
- mysql_close($dbhandle);
- ?>
Add Comment
Please, Sign In to add comment