Guest User

Untitled

a guest
Apr 7th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.94 KB | None | 0 0
  1. <?php
  2.     $username = "root";
  3.     $password = "77applebed1250";
  4.     $hostname = "localhost";
  5.  
  6.     //connection to the database
  7.     $dbhandle = mysql_connect($hostname, $username, $password)
  8.     or die("Unable to connect to server MySQL");
  9.     echo "Connected to MySQL<br>";
  10.  
  11.     //select a database to work with
  12.     $selected = mysql_select_db("forum2",$dbhandle)
  13.     or die("Could not select db forum2");
  14.  
  15.     //execute the SQL query and return records
  16.     $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)");
  17.  
  18.     echo "<script language='JavaScript'>
  19.    newwindow=window.open('','risultato','height=500,width=500');
  20.    </script>";
  21.  
  22.     //fetch tha data from the database
  23.  
  24.  
  25.     // Open a known directory, and proceed to read its contents
  26.     $dir = "/var/www/virtual/unibosca.com/htdocs/public/mkportal/modules/downloads/file";
  27.     if (is_dir($dir)) {
  28.         if ($dh = opendir($dir)) {
  29.             while (($file = readdir($dh)) !== false) {
  30.                 while ($row= mysql_fetch_array($result))
  31.                 {
  32.                    
  33.                     $basefilename = preg_replace("/(.*)\.([^.]+)$/","\\1", $file);  
  34.                    
  35.                     $filename = preg_replace("/(.*)\.([^.]+)$/","\\1", $row['file']);
  36.                     if (preg_match('/'.$row['file'].'/i',$basefilename)) salva_file($file,$row['file'],$row['evento']);
  37.                 }
  38.             }
  39.             closedir($dh);
  40.         }
  41.     }
  42.  
  43.     function salva_file($originale,$nuovo,$categoria)
  44.     {
  45.         if (!is_dir($dir.'/riorganizzato/'.$categoria)) mkdir ($dir.'/riorganizzato/'.$categoria,0777,true);
  46.         copy($originale,$dir.'/riorganizzato/'.$categoria.'/'.$nuovo);
  47.         echo $originale." copiano in /".$categoria."/".$nuovo;
  48.         return true;
  49.     }
  50.     //close the connection
  51.     mysql_close($dbhandle);
  52. ?>
Add Comment
Please, Sign In to add comment