我正在尝试将图像保存在文件夹中并将路径保存在数据库中,但是我不能这样做。当我仅插入姓名和电话都可以,但是当我添加输入类型文件时,它将保存我的姓名和电话号码,但不保存图像路径,也不将图像上传到文件夹中。这是代码:
PED.PHP
<form class="form-horizontal form-label-left input_mask" method="post" id="add" name="add" enctype="multipart/form-data">
<div class="form-group"" >
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">CLIENT</label>
<div class="col-md-9 col-sm-9 col-xs-12" style="float: left; width:70px;">
<input type="text" style="width:200px; float:left;"name="client" class="form-control" placeholder="" >
</div>
</div>
<div class="form-group" style="border: 1px ; height:45px;" >
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">PHONE:
</label>
<div class="col-md-9 col-sm-9 col-xs-12" style="float: left; width:70px;">
<input type="text" style="width:200px; float:left;"name="phone" class="form-control" placeholder="" >
</div>
</div>
<div class="form-group" style="border: 1px ; height:45px;" >
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">PICTURE:
</label>
<div class="col-md-9 col-sm-9 col-xs-12" style="float: left; width:70px;">
<input type="file" name="uploadImage" id="uploadImage">
</div>
</div>
<div class="ln_solid"></div>
<div class="form-group">
<button id="save_data" type="submit" class="btn btn-success">Guardar</button>
</div>
</div>
</form
这里我收到所有数据:ADDPED.PHP
<?php
date_default_timezone_set('America/Mexico_City');
session_start();
if (empty($_POST['name'])) {
$errors[] = "Selecciona una tienda";
} else if (empty($_POST['cliente'])){
$errors[] = "Ingrese cliente";
} else if (
!empty($_POST['name']) &&
!empty($_POST['cliente'])
){
include "../config/config.php";
$client = $_POST["cliente"];
$phone = $_POST["telefono"];
("images/fotos/" . $_FILES["uploadImage"]["name"]);
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br>";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"images/fotos/" . $_FILES["file"]["name"]);
}
$sql="insert into pedido (client,phone,image) value ('$client','$phone','".$_FILES['uploadImage']['name']."')";
$query_new_insert = mysqli_query($con,$sql);
if ($query_new_insert){
$messages[] = "Tu ticket ha sido ingresado satisfactoriamente.";
} else{
$errors []= "Lo siento algo ha salido mal intenta nuevamente.".mysqli_error($con);
}
} else {
$errors []= "Error desconocido.";
}
if (isset($errors)){
?>
<div class="alert alert-danger" role="alert">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Error!</strong>
<?php
foreach ($errors as $error) {
echo $error;
}
?>
</div>
<?php
}
if (isset($messages)){
?>
<div class="alert alert-success" role="alert">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>¡Bien hecho!</strong>
<?php
foreach ($messages as $message) {
echo $message;
}
?>
</div>
<?php
}
?>
上传文件的最大默认文件大小为2MB。但是您可以在配置中更改它,还可以检查数据库中使用的数据类型及其最大限制。最好将图像上传到文件夹中,然后将文件名插入数据库。它还将提高系统性能。查看this示例以将图像上传到数据库。