我似乎无法使用 PHP 上传文件。据我所知,一切都结束了。我什至甚至去挖掘旧教科书并直接从文本中复制示例,但仍然没有成功。
起初,我认为这是保存文件的目录权限的问题,所以我将权限更改为 777,但仍然没有。如果有人有任何建议,我会全力以赴:/
这是代码(HTML):
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="file1">
<br/>
<input type="submit" value="Upload">
</form>
PHP 文件:
<?php
$tmp_name = $_FILES['file1']['tmp_name'];
$path = getcwd() . DIRECTORY_SEPARATOR . 'images';
$name = $path . DIRECTORY_SEPARATOR . $_FILES['file1']['name'];
$success = move_uploaded_file($tmp_name, $name);
if($success) {
$upload_message = $name . ' has been uploaded.';
echo "$upload_message";
} else {
echo "something went wrong :(";
}
?>