I am trying to upload a file to my directory through html
and I manipulate it from the server with php
in such a way that it is saved in the directory that I indicate, but I have not been able to, the file arrives and when I try it the way in that the page tells me , but it doesn't work, I get this error:
Warning : move_uploaded_file(/Jomar/induccion/documents/mision, vision/OBJETIVOS JOMAR INVERSIONES SAS 2019.pdf): failed to open stream: No such file or directory in C:\xampp\htdocs\Jomar\induccion\controllers\UploadFiles. php on line 9
Warning : move_uploaded_file(): Unable to move 'C:\xampp\tmp\php32BA.tmp' to '/Jomar/induccion/documents/mision, vision/OBJETIVOS JOMAR INVERSIONES SAS 2019.pdf' in C:\ xampp\htdocs\Jomar\induction\controllers\UploadFiles.php on line 9
This is the code php
:
<?php
require_once "../controllers/FilesController.php";
$dir = "/Jomar/induccion/documents/";
print_r($_FILES);
if($_FILES["mision_vision"] != null){
$fichero = "{$dir}mision, vision/".basename($_FILES["mision_vision"]["name"]);
FilesController::deleteFiles($dir."mision, vision/");
if(move_uploaded_file($_FILES["mision_vision"]["tmp_name"], $fichero)){
echo "Subido correctamente";
}else{
echo "Error al intentar subir";
}
}
?>
Capture of the directories:
The response to doing var_dump
and the[error]
array(1) {
["mision_vision"]=>
array(5) {
["name"]=>
string(40) "OBJETIVOS JOMAR INVERSIONES SAS 2019.pdf"
["type"]=>
string(15) "application/pdf"
["tmp_name"]=>
string(23) "C:\xampp\tmp\php303.tmp"
["error"]=>
int(0)
["size"]=>
int(207419)
}
}
Error al intentar subir: 0
UPDATE
<?php
require_once "../controllers/FilesController.php";
define ('SITE_ROOT', realpath(dirname(__FILE__)));
$dir = "/Jomar/induccion/documents/";
print_r($_FILES);
if(isset($_FILES["mision_vision"]) && $_FILES["mision_vision"] != null){
$fichero = SITE_ROOT."{$dir}".basename($_FILES["mision_vision"]["name"]);
FilesController::deleteFiles($dir."mision, vision/");
if(move_uploaded_file($_FILES["mision_vision"]["tmp_name"], $fichero)){
echo "Subido correctamente";
}else{
echo "Error al intentar subir";
}
}
?>
Solved, what I did to solve the problem was to put
$_SERVER["DOCUMENT_ROOT"]
, after searching exhaustively I got the answer from this forum (it is in English) in the same way I show the way in which I applied it to solve my problem.Thanks to @A. Cedano for his help, I hope someone also finds it useful.