[英]PHP Move_uploaded_file not moving my file to directory
I am making an image uploading feature for a program I am developing however I cant seem to get move_uploaded_file to actually move my file and I am not sure why.我正在为我正在开发的程序制作图像上传功能,但是我似乎无法让 move_uploaded_file 实际移动我的文件,我不知道为什么。
I am receiving the form data as I can see the data when I use the print_r function print_r($_FILES)
我正在接收表单数据,因为我在使用 print_r 函数时可以看到数据
print_r($_FILES)
My directory struct is as follows root->app->lib->uploadCode.php
and root->app->images
我的目录结构如下
root->app->lib->uploadCode.php
和root->app->images
I dont get any errors.我没有收到任何错误。 I am running this on ubuntu 16.04 with php7 installed
我在安装了 php7 的 ubuntu 16.04 上运行它
Here is my code.这是我的代码。
<?php
error_reporting(E_ALL);
if(!empty($_FILES['newImage']['name']))
{
$fname = $_FILES['newImage']['name'];
$fext = explode(".",$fname);
$sex = array("jpg", "jpeg", "JPG", "JPEG", "png", "PNG");//Supported extensions
//Check if file extension supported
$extRes = array_intersect($fext, $sex);//Checks to see if file uploaded extension exists in the supported extension array
if(count($extRes) == 1)
{
print_r($_FILES);
$name = $_FILES['newImage']['name'];
$ext = end($fext);
$tmp = $_FILES['newImage']['tmp_name'];
$path = '/../images/';
$newName = uniqid().".".$ext;
/*if(move_uploaded_file($tmp,$path.$newName))
{
echo "uploaded";
}
else
{
echo "not uploaded";
echo $path.$newName;
}*/
move_uploaded_file($tmp,$path.$newName);
}
elseif(count($extRes) > 1)
{//More than just one file extension was found possibly something like image.png.jpg
echo 02;
}
else
{// Nothing was found so wrong file type was used
echo 01;
}
}else
{//Do if no image was uploaded
echo 00;
}
` `
Either remove the opening slash from $path = '/../images/';
从
$path = '/../images/';
删除开始斜杠$path = '/../images/';
or set the full path, eg /home/username/images/
for example或设置完整路径,例如
/home/username/images/
It was a permission issue.这是一个许可问题。
I had to do the following to my www/html directory.我必须对我的 www/html 目录执行以下操作。
sudo chown -R username:www-data /var/www/html/
sudo chmod 775 /var/www/html/
sudo chmod g+s /var/www/html
Once I ran those commands I was able to upload sudo chown -R username:www-data /var/www/html/
sudo chmod 775 /var/www/html/
sudo chmod g+s /var/www/html
一旦我运行了这些命令,我就可以上传
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.