php - 在 macOS Catalina 中上传图像时出现以下错误
问题描述
当我所做的只是将文件上传到数据库中时,我的代码运行良好。但是当我尝试将它也存储在文件夹中时,我收到了警告:
move_uploaded_file(files/picture.jpg): 无法打开流: 权限被拒绝和 move_uploaded_file(): 无法将 '/Applications/XAMPP/xamppfiles/temp/phpB59AaC' 移动到 'files/picture.jpg
I'm also tried about permissions and echo the path and directory give me currently path
I think I'm missing something important but i cant figure out here is my codes:
html code->>>
<form action="" enctype="multipart/form-data" method="post">
<input name="myfile" type="file">
<button>
go!
</button>
</form>
phpcode->>>
<?php
if (isset($_FILES['myfile'])){
$file=$_FILES['myfile'];
$fileName=$file['name'];
$fileSize=$file['size'];
$fileTmp=$file['tmp_name'];
$fileType=$file['type'];
$fileError=$file['error'];
$uploadOk = 1;
$target='files/';
$newName='picture';
if ($fileType != 'image/jpg' and $fileType != 'image/jpeg'){
$uploadOk = 0;
}
if ($fileSize > 5242880){
$uploadOk = 0;
}
if ($uploadOk == 1){
$ext=pathinfo($fileName,PATHINFO_EXTENSION);
$target=$target . $newName . '.' . $ext;
move_uploaded_file($fileTmp, $target);
}
}
?>
解决方案
可能是权限的问题。你可以尝试更改文件夹的权限,让每个人都可以读写。 试试这样
推荐阅读
- android - 为什么 ionic cordova 只是偶尔构建?
- java - 将字符串(具有转义字符、换行符)转换为纯字符串
- javascript - 参数可以用作默认值吗
- python - 有没有办法在 python 中使用 kubernetes 库读取秘密数据?
- php - 警告嵌套引用的 foreach 循环,确保数组修改(如果有)符合您的预期
- python - 如何在python中将列值转换为新列?
- reactjs - 我已经在 firebase 上部署了 React 项目,但它没有显示我的网站。其节目欢迎页面
- assembly - X86 程序集:.text.startup 部分和 .text 部分有什么区别
- android - 使用 android studio 模拟器在 android api <24 中测试 Google 计费
- docker - 您的构建运行失败:无法读取提交 xxxxxxxx