php:简单的音乐上传与展示
发布日期:2021-05-04 18:47:58 浏览次数:29 分类:精选文章

本文共 3143 字,大约阅读时间需要 10 分钟。

PHP ???????????

???

PHP ???????????????????????????? PHP ??????????????????????????????????????

  • file_get_contents??????????
  • json_decode????? JSON ??????
  • file_put_contents???????????
  • move_uploaded_file???????????
  • ????

    ???????????

    .
    ??? add.php
    ??? bootstrap.css
    ??? list.php
    ??? storage.json
    ??? uploads??????
    ??? ...

    ????

    list.php - ??????

    ????

    ????


    ??
    ?? ?? ?? ?? ??

    add.php - ????

    1024 * 1024) {
    $error_message = '?????????1MB?';
    return;
    }
    // ????????
    $allowed_types = ['audio/mp3', 'audio/wma'];
    if (!in_array($source['type'], $allowed_types)) {
    $error_message = '???????';
    return;
    }
    // ??????
    $target = './uploads/' . uniqid() . '-' . $source['name'];
    if (!move_uploaded_file($source['tmp_name'], $target)) {
    $error_message = '????????';
    return;
    }
    // ??????
    if (empty($_FILES['images']['name'])) {
    $error_message = '?????';
    return;
    }
    $images = $_FILES['images'];
    if ($images['error'] !== UPLOAD_ERR_OK) {
    $error_message = '??????';
    return;
    }
    // ????????
    if ($images['size'] > 1024 * 1024) {
    $error_message = '?????????1MB?';
    return;
    }
    // ????????
    $allowed_image_types = ['image/jpeg', 'image/png', 'image/gif'];
    if (!in_array($images['type'], $allowed_image_types)) {
    $error_message = '???????';
    return;
    }
    // ??????
    $image_target = './uploads/' . uniqid() . '-' . $images['name'];
    if (!move_uploaded_file($images['tmp_name'], $image_target)) {
    $error_message = '??????';
    return;
    }
    // ????????.json
    $origin = json_decode(file_get_contents('storage.json'), true);
    $origin[] = [
    'id' => uniqid(),
    'title' => $_POST['title'],
    'artist' => $_POST['artist'],
    'images' => $image_target,
    'source' => $target,
    ];
    $json = json_encode($origin);
    file_put_contents('storage.json', $json);
    header('Location: list.php');
    }
    ?>
    ?????

    ?????


    上一篇:mysql:php操作mysql基础总结
    下一篇:php:header函数的作用

    发表评论

    最新留言

    做的很好,不错不错
    [***.243.131.199]2025年04月22日 15时39分58秒