Guest User

Untitled

a guest
Apr 7th, 2018
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 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. // Open a known directory, and proceed to read its contents
  25. $dir = "/var/www/virtual/unibosca.com/htdocs/public/mkportal/modules/downloads/file/";
  26. $dir2 = "/var/www/virtual/unibosca.com/htdocs/public/mkportal/modules/downloads/";
  27. if (is_dir($dir)) {
  28. if ($dh = opendir($dir)) {
  29. while (($file = readdir($dh)) !== false) {
  30. $name = $file;
  31.  
  32. while ($row= mysql_fetch_array($result))a--
  33. {
  34.  
  35. //$basefilename = preg_replace("/(.*)\.([^.]+)$/","\\1", $file);
  36. $basefilename = pathinfo($file, PATHINFO_FILENAME);
  37. //$filename = preg_replace("/(.*)\.([^.]+)$/","\\1", $row['file']);
  38. $filename = pathinfo($row['file'], PATHINFO_FILENAME);
  39. $pattern = "/".preg_quote($filename)."/";
  40. //echo $pattern.",".$filename."<br/>\n";
  41. echo $name;
  42. if (preg_match($pattern,$basefilename))
  43. {
  44. // salva_file($file,$row['file'],$row['evento']);
  45. $match = true;
  46. }
  47. if( $match ) continue;
  48. }
  49. }
  50. closedir($dh);
  51. }
  52. }
  53.  
  54. function salva_file($originale,$nuovo,$categoria)
  55. {
  56. if (!is_dir($dir2.'/riorganizzato/'.$categoria)) mkdir ($dir2.'/riorganizzato/'.$categoria,0777,true);
  57. copy($dir.'/'.$originale,$dir2.'/riorganizzato/'.$categoria.'/'.$nuovo);
  58. echo $originale." copiano in /".$categoria."/".$nuovo;
  59. return true;
  60. }
  61. //close the connection
  62. mysql_close($dbhandle);
  63. ?>
Add Comment
Please, Sign In to add comment