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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀