1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- $path = '/var/www/upload/upload_avail/';
- $link = mysql_connect("db.usic.lan", "site", $argv[1]);
- mysql_select_db("site", $link);
- $query = "select * from upload";
- $res = mysql_query($query, $link);
- $row = array();
- while($r = mysql_fetch_array($res, MYSQL_ASSOC)) {
- $row[] = $r;
- }
- $n = sizeof($row);
- for($i=0; $i<$n; ++$i) {
- $old = $row[$i]["url"];
- $hash = substr($old,($a=strrpos($old, '/')+1), strrpos($old, '.')-$a);
- if (!mkdir($path.$hash)) {
- echo $path.$hash."\n"; exit(1);
- }
- $new = $path.$hash.'/'.$row[$i]["filename"];
- $command = "cp ".$old." ".$new;
- echo shell_exec($command);
- $query = "update upload set url='".$new."' where id='".$row[$i]["id"]."'";
- mysql_query($query);
- echo shell_exec("rm ".$old);
- }
- echo "ok";
- mysql_close($link);
- ?>
|