我在我的 C 驱动器 (c:/artwork) 中创建了一个文件夹,我用它来通过 php 中的表单上传文件,如下所示:
<input name="file" type="file">
问题是,当文件上传后,我转到文件夹并尝试打开文件时,我收到以下消息: 照片库无法打开此图片,因为您没有访问文件位置的权限
如果我手动将图片复制并粘贴到同一文件夹中,则没有问题。我可以完美打开和查看图片!
我猜这一定是通过 php 上传时的权限问题,但究竟是什么?我该如何解决?
谢谢
编辑(添加代码)
$destination = 'c:/public_html/discography/artwork/'; // path to the upload folder
if (is_dir($destination) && is_writable($destination)) {
// if file already exists, ask what to do
// upload the file
$ok = move_uploaded_file($_FILES['file']['tmp_name'], $destination . $_FILES['file']['name']);
// if file uploaded, go ahead an insert record in database
if ($ok) {
$stmt = $conn->stmt_init(); // initialize a prepared statement
$stmt->prepare($sql);
$stmt->bind_param('s', $_FILES['file']['name']);
$stmt->execute();
$stmt->free_result(); // free the database resources for other queries
// if success
if ($stmt->affected_rows > 0) {
$success = true;
} else {
$err_msg = $stmt->error;
}
$stmt->close(); // close statement
}
} else {
$err_msg = "'$destination' must be a valid, writable directory!";
}
最佳答案
如果您没有在 php.ini 中设置“upload_tmp_dir”指令,那么文件将保存在临时文件夹中。在您的情况下,如果您使用的是 IIS,则为 C:\Windows\Temp,因此它会继承该目录的权限,而不是 c:/public_html/discography/artwork/。
要解决这个问题,要么设置 Temp 目录的权限,要么在 php.ini 中定义另一个位置来存储 tmp 文件。
关于php - 通过 php 上传到本地驱动器上的文件夹时出现权限问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7042988/