I have the directory photo_gallery (with 777 permissions) created in the same level as the Noticias.php file
It gives me no error, but the file is not showing in the photo_gallery folder.
This is my PHP code:
$error=array();
$extension=array("jpeg","jpg","png","gif");
foreach($_FILES["imagenes"]["tmp_name"] as $key=>$tmp_name)
{
$file_name=$_FILES["imagenes"]["name"][$key];
$file_tmp=$_FILES["imagenes"]["tmp_name"][$key];
$ext=pathinfo($file_name,PATHINFO_EXTENSION);
if(in_array($ext,$extension))
{
if(!file_exists("photo_gallery/".$file_name))
{
move_uploaded_file($file_tmp=$_FILES["imagenes"]["tmp_name"][$key],"photo_gallery/".$file_name);
}
else
{
$filename=basename($file_name,$ext);
$newFileName=$filename.time().".".$ext;
move_uploaded_file($file_tmp=$_FILES["imagenes"]["tmp_name"][$key],"photo_gallery/".$newFileName);
}
}
else
{
array_push($error,"$file_name, ");
}
}
And HTML:
<form action="Noticias.php" method="post" id="myform" enctype="multipart/form-data">
div class="form-group">
<p>Imágenes</p>
<input type="file" name="imagenes[]" class="form-control" id="imagenes" placeholder="Imágenes" multiple="multiple"/>
</div>
<button type="submit" class="btn btn-primary">Guardar</button>
</form>
move_uploaded_file() needs as second parameter the folder and the filename of the new location.
You should to do something like this:
move_uploaded_file($_FILES["imagenes"]["tmp_name"][$key], "photo_gallery/your_filename.png");
I hope that help you.
Regards.
give the file path as
./photo_gallery/
try liker this. This may help you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.