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条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?