doucheng7234 2012-10-01 05:14
浏览 86
已采纳

文件上传到多个目录中

This is a script that Upload a file in all directory. But when i run it, its only upload One time and then fail to upload . whats wrong in this code ?

function read_directory($p_pathname)
{
$d = dir ($p_pathname);
$target = $p_pathname; 
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target.$_FILES['uploaded']['name'])) 
{
    echo $target. "Done<br>";
} 
else 
{
    echo $target."Sorry<br>";
}
while (($file = $d->read()) !== false)
{
    if (($file != ".") and ($file != ".."))
    {
        $filetype = filetype ("{$d->path}/{$file}");

        if ($filetype == "dir")
        {
            read_directory ("{$d->path}/{$file}");
        }
        else
        {
            // echo "\tFILE: {$d->path}/{$file}
";
        }
    }
}
$d->close;
}
  • 写回答

3条回答 默认 最新

  • doupao6698 2012-10-27 06:12
    关注

    Use copy() instead of move_uploaded_file(). move_uploaded_file() deletes the source file when it's done, so you can't use it multiple times on the same file. copy() leaves the original file alone, so you can do it as many times as you want.

    When the script exits, PHP automatically removes the temp file that was uploaded if it doesn't get moved by the script.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度