Move_uploaded_file (...): Could not open stream: no such file or directory

I am trying to insert images in my database with PHP and MySQL with a temporary folder.

I am using laravel and this is my controller:

if(isset($_FILES['img_masc']))
{
    $img=$_FILES['img_masc']['name'];
    $ruta= $_FILES['img_masc']['tmp_name'];
}

$destino='../../../Perf_Masc/'.$img;
$masc->img=$destino;
//copy($ruta, $destino);
move_uploaded_file($ruta, $destino); //line 49

It's my opinion:

<form method="POST" action="/RegMasc" enctype= "multipart/form-data" >
    <div>
        <input required name="img_masc" type="file"/>
    </div>

That's my fault:

ErrorException on line 49: move_uploaded_file (../../../Perf_Masc/AF5.jpg): could not open the stream: there is no such file or directory

I try so many things as well with the copy function and it doesn't work anyway

+4
source share
2 answers

In your configuration file or in some shared file, specify your path below

define('DOCROOT', $_SERVER['DOCUMENT_ROOT'].'<YOUR PROJECT DIRECTORY>/');

Include this generic php in all your class files.

Then

 $destino= DOCROOT.'Perf_Masc/'.$img; // HERE DOCROOT is defined in config.
+8
source

Change your slash to backslash.

//Define back slash so that you can use it anywhere later
defined("DS") ? null : define("DS", DIRECTORY_SEPARATOR);
// Define your website siteroot
defined("SITE_ROOT") ? null : define("SITE_ROOT", "C:".DS."wamp".DS."www".DS."your_website");

$file_name=$_FILES['file']['name'];
$file_tmp=$_FILES['file']['tmp_name'];
$file_upload_to=SITE_ROOT . DS . "Perf_Masc";

move_uploaded_files($file_tmp, $file_upload_to . DS . $file_name);

, php , echo __DIR__ PHP 5.3 , echo dirname(__FILE__).

+1

Source: https://habr.com/ru/post/1622304/


All Articles