【发布时间】:2022-11-21 06:09:12
【问题描述】:
我在使用 php 保存文件时遇到问题。我尝试做类似 mediafire 或 google drive 的事情。 它是路径变量的代码:
$dir = "../src/users/$name/";
有我的代码:
<?php
session_start();
include "../src/db_conn.php";
if(isset($_SESSION['login'])) {
$name = $_SESSION['login'];
$dir = "../src/users/$name/";
$file = $dir.basename($_FILES['file']['name']);
$imageFileType = strtolower(pathinfo($file,PATHINFO_EXTENSION));
$upload = 1;
if(file_exists($file)) {
header("Location: ../index.php?error=Sorry, file already exsist.");
$upload = 0;
}
if($_FILES['file']['size'] > 500000) {
header("Location: ../index.php?error=Sorry, your file is too large.");
$upload = 0;
}
if($upload == 0) {
header("Location: ../index.php?error=Sorry, your file was not uploaded.");
exit();
}else {
if(move_uploaded_file($_FILES['file']['tmp_name'], $file)) {
header("Location: ../index.php?success=File " . htmlspecialchars( basename( $_FILES['file']['name'])). " has been uploaded");
exit();
} else {
header("Location: ../index.php?error=There was and error uploading your file.");
}
}
}
?>
这可行,但我无法在其他服务器上保存文件...
【问题讨论】:
标签: php web file-upload server disk