upload_dir.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. # script for moving from one upload_dir to another
  3. $path = '/var/www/upload/upload_avail/';
  4. //print_r( shell_exec("ls -la ".$path."; ls -ld ".$path));
  5. $link = mysql_connect("db.usic.lan", "site", $argv[1]);
  6. mysql_select_db("site", $link);
  7. $query = "select * from upload";
  8. $res = mysql_query($query, $link);
  9. //$n = mysql_num_rows($res);
  10. $row = array();
  11. while($r = mysql_fetch_array($res, MYSQL_ASSOC)) {
  12. $row[] = $r;
  13. }
  14. $n = sizeof($row);
  15. // copying to new dir, update the db and deleting from old dir
  16. for($i=0; $i<$n; ++$i) {
  17. $old = $row[$i]["url"];
  18. $hash = substr($old,($a=strrpos($old, '/')+1), strrpos($old, '.')-$a);
  19. if (!mkdir($path.$hash)) {
  20. echo $path.$hash."\n"; exit(1);
  21. }
  22. $new = $path.$hash.'/'.$row[$i]["filename"];
  23. $command = "cp ".$old." ".$new;//echo $command."\n\n";
  24. echo shell_exec($command);
  25. $query = "update upload set url='".$new."' where id='".$row[$i]["id"]."'";
  26. mysql_query($query);
  27. echo shell_exec("rm ".$old);
  28. }
  29. echo "ok";
  30. /*for($i=0; $i<$n; ++$i) {
  31. echo "id = ".$row[$i]["id"]."\n";
  32. echo "filename = ".$row[$i]["filename"]."\n";
  33. echo "url = ".$row[$i]["url"]."\n";
  34. echo "\n";
  35. }*/
  36. mysql_close($link);
  37. ?>