重复问题:无法使用表单将文件上传到文件夹
P粉764785924
P粉764785924 2023-08-08 21:57:36
[PHP讨论组]

admin.php:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Admin</title>
</head>
<body>
    <form action="upload.php" method="POST" enctype="multipart/form-data">
        Image: <input type="file" name="image">
        <br>
        Sale or Rent: <input type="text" name="isForSale">
        <br>
        Price: <input type="text" name="price">
        <br>
        Location: <input type="text" name="location">
        <br>
        Area: <input type="text" name="area">
        <br>
        Bedrooms: <input type="text" name="bedrooms">
        <br>
        <button type="submit">Upload</button>
    </form>
</body>
</html>

upload.php:

<?php
    if(isset($_POST['submit'])) {
        $file = $_FILES['image'];

        $fileName = $_FILES['image']['name'];
        $fileTmpName = $_FILES['image']['tmp_name'];
        $fileSize = $_FILES['image']['size'];
        $fileError = $_FILES['image']['error'];
        $fileType = $_FILES['image']['type'];

        $fileExt = explode('.',$fileName);
        $fileActExt = strtolower(end($fileExt));

        $allow = array('jpg','jpeg','png');

        if(in_array($fileActExt,$allow)) {
            if($fileError === 0) {
                $fileNewName = uniqid('', true).".".$fileActExt;
                $fileDestination = 'FamilyRealEstate/FamilyRealEstateImages/uploads'.$fileNewName;
                move_uploaded_file($fileTmpName, $fileDestination);
                header("Location: admin.php?uploadsuccess");
            } else {
                echo "Error uploading your file";
            }
        } else {
            echo "You cannot upload files of this type.(Only jpg, jpeg, png)";
        }
    }
?>

我正在尝试将图片上传到网络并在文件夹中保存它。这似乎不起作用。它只是去到空白页面(upload.php)。可能是因为文件夹的权限,然而我正在使用Ubuntu,并且非常新,所以我真的不知道如何修复它。

P粉764785924
P粉764785924

全部回复(1)
P粉530519234

Your submit button should contain the name attribute with the submit value:

<button type="submit" name="submit">Upload</button>
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号