I've followed a small tutorial so that i can upload a file to a server, this file should be moved into img/profile/ and then it reads from there.
My tree is like this (img and profile are the folders):
updatepp.php icon-profile.png img and profile inside of img
I went into my folders and checked the permissions and it says i am able to write to this file.
Inside of updatepp.php is the fcode for the profilepic uploading
if(isset($_FILES['profile']) === true){
if(empty($_FILES['profile']['name']) === true){
echo 'please choose a file';
}else{
//checks
$allowed = array('jpg', 'jpeg', 'png', 'gif');
$file_name = $_FILES['profile']['name'];
$file_extn = strtolower(end(explode('.', $file_name)));
$file_temp = $_FILES['profile']['tmp_name'];
if(in_array($file_extn, $allowed) === true){
$file_path = 'img/profile/' . substr(md5(time()),0,10) . '.' . $file_extn;
if(move_uploaded_file($file_temp, $file_path)){
echo "succes " . $file_path;
$result = $db->prepare("UPDATE users SET profile=:profile WHERE user_id=:user");
$result->bindParam(':profile', $file_path);
$result->bindParam(':user', $user);
$result->execute();
}else{
echo "failure";
}
}else{
echo 'incorrect file type. Allowed: ';
echo implode(', ', $allowed);
}
}
}
The file is uploaded to the database and the message succes $file_path
is shown on the screen. However when i look into the folder I see that the file has NOT been moved.
I am hosting this on a virtual ubuntu client with LAMP stack installed and i use shared folders between the host and the virtual machine.
I would assume that the folder doesn't exist, but it clearly does.