move_uploaded_file(...):无法打开流:没有这样的文件或目录 [英] move_uploaded_file(...): failed to open stream: No such file or directory
问题描述
我尝试通过一个临时文件夹在PHP和MySQL数据库中插入图像.
I try to insert images in my database with PHP and MySQL with a temporary folder.
我使用laravel,这是我的控制器:
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
这是我的观点:
<form method="POST" action="/RegMasc" enctype= "multipart/form-data" >
<div>
<input required name="img_masc" type="file"/>
</div>
这是我的错误:
第49行的ErrorException: move_uploaded_file(../../../Perf_Masc/AF5.jpg):无法打开流:没有这样的文件或目录
ErrorException in line 49: move_uploaded_file(../../../Perf_Masc/AF5.jpg): failed to open stream: No such file or directory
我尝试了很多事情,还尝试了复制功能,但还是无法正常工作
I try with so much things and also with the copy function and is not working anyway
推荐答案
在您的Config文件或某些常见文件中,如下所示定义路径
In your Config file or some common file define your path as below
define('DOCROOT', $_SERVER['DOCUMENT_ROOT'].'<YOUR PROJECT DIRECTORY>/');
在您的所有类文件中包含此通用php.
Include this common php in all your class file.
然后
$destino= DOCROOT.'Perf_Masc/'.$img; // HERE DOCROOT is defined in config.
这篇关于move_uploaded_file(...):无法打开流:没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!