doumi1884 2014-05-29 08:44
浏览 44
已采纳

PHP上传图像时间戳文件名严格标准错误

I have the below script and when its ran I get an error about Strict Standards, could someone help at all? I am trying to set the current timestamp as the filename so that too.

<br /> <b>Strict Standards</b>:  Only variables should be passed by
reference in
<b>/home/user/public_html/domain.com/upload.php</b>
on line <b>15</b><br /> Upload: screenshot-05.png<br />Type:
image/png<br />Size: 49.2109375 Kb<br />Stored in: uploads/1401352853

PHP

if(empty($_FILES['file'])) {
  exit();
}


$allowedExts = array("jpg", "jpeg", "gif", "png");
$extension = end(explode(".", $_FILES["file"]["name"]));

if ($_FILES["file"]["type"] == "image/gif" || $_FILES["file"]["type"] == "image/jpg" || $_FILES["file"]["type"] == "image/jpeg" || $_FILES["file"]["type"] == "image/png" && $_FILES["file"]["size"] < 2500000 && in_array($extension, $allowedExts)) {
    if ($_FILES["file"]["error"] > 0) {
        echo "Error: " . $_FILES["file"]["error"] . "<br />";
    } else {
        $unixtime = time();
        $fname = 'uploads/'. $unixtime;
        move_uploaded_file($_FILES["file"]["tmp_name"], $fname);

        echo "Upload: " . $_FILES["file"]["name"] . "<br />";
        echo "Type: " . $_FILES["file"]["type"] . "<br />";
        echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
        echo "Stored in: " . $fname;
    }
} else {
    echo "Invalid file type";
}

Edit: Line 15 is -> $extension = end(explode(".", $_FILES["file"]["name"]));

  • 写回答

1条回答 默认 最新

  • dongtuo1482 2014-05-29 08:57
    关注
    $bits = explode(".", $_FILES["file"]["name"]);
    $extension = end($bits);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料