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.
I am receiving the form data as I can see the data when I use the print_r function print_r($_FILES)
My directory struct is as follows root->app->lib->uploadCode.php
and root->app->images
I dont get any errors. I am running this on ubuntu 16.04 with php7 installed
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/';
or set the full path, eg /home/username/images/
for example
It was a permission issue.
I had to do the following to my www/html directory.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.