使用php

时间:2016-12-29 00:30:25

标签: php file-upload

我想使用php将图像上传到文件。我一直在简化代码,但它仍然无法正常工作。一旦弄清楚哪些错误,我就会添加参数。这是我的文件upload.php

<html>
<body>

<form action="upload.php" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="upload" id="upload">
    <input type="submit" value="Upload Image" name="submit">
</form>

</body>
</html>

<?php
if(isset($_POST["submit"])) {
$pathway= "uploads/";
$target_file = $pathway . basename($_FILES["upload"]["name"]);
    if (move_uploaded_file($_FILES["upload"]["tmp_name"], $target_file)) {
        echo "The file ". basename( $_FILES["upload"]["name"]). " has been uploaded.";
    }
}
?>

我已创建文件夹&#34;上传&#34;,但图片未添加到其中。

1 个答案:

答案 0 :(得分:0)

首先,您必须确保php.ini中的属性file_uploads = on 文件

第二步确保将upload_max_filesize设置为您想要的大小

然后看到这段代码

1