I'm trying to upload an image to a specific directory but the function moveTo
is not moving the image.
public function uploadRecipeImageAction() {
if ($this->request->hasFiles() == true) {
$file = $this->request->getUploadedFiles()[0];
$target_file = '/uploads/ketogenic-recipes/'.preg_replace("/[^a-z0-9\_\-\.]/i", '', basename($file->getName()));
$file->moveTo($_SERVER['DOCUMENT_ROOT'] . $target_file);
}
return $target_file;
}
The function works fine locally but it's not working in server. There are no errors in logs
uploads
and ketogenic-recipes
directory permissions are set to 0775
PHP Version 7.2.20
Phalcon version is 3.4
var_dump($_SERVER['DOCUMENT_ROOT']) = string(30) "/home/web/public_html/test2"
var_dump($target_file); = string(42) "/uploads/ketogenic-recipes/harrypotter.jpg"