dongpo8702 2012-03-28 09:43
浏览 23
已采纳

Uploadify - 将临时名称更改为时间并上传 - PHP

I want to change the name of the uploaded file, to the current time by using time() but i cant seem to figger out where to insert the new time name ?

can some one try look at this ?

<?php
if (!empty($_FILES)) {
    $newName = time(); <-- Should be the new temp name, insted of the uploaded one.
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_GET['folder'] . '/';
    $targetFile =  str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];

    move_uploaded_file($tempFile,$targetFile);
}

echo '1';
?>
  • 写回答

4条回答 默认 最新

  • duanba7498 2012-03-28 09:45
    关注

    $_FILES['Filedata']['name'] has your filename, you can replace that but first you need to get the file's extension if it's not the same all the time.

    $p = pathinfo($_FILES['Filedata']['name']);
    $newName = time() . "." . $p['extension'];
    $targetFile =  str_replace('//','/',$targetPath) . $newName;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?