[英]My variable $_FILES doesn't run
使用这种形式:
<form id="form1" name="form1" method="post" action="insertartrabajo.php" enctype="multipart/form-data">
<legend>formato vertical</legend>
<br />
<label for="cserv">Servicio:</label>
<select name="cserv">
<option value="NULL">Seleccione un servicio</option>
<?php
$sql="SELECT * FROM servicios GROUP BY servicios.nombre";
$resultado=mysql_query($sql);
while($fila=mysql_fetch_array($resultado)){
?>
<option value="<?php echo $fila["nombre"]; ?>"><?php echo $fila["nombre"]; ?></option>
<?php } ?>
</select>
<br>
<label for="cdirv">Direccion:</label>
<input name="cdirv" type="text">
<br>
<label for="cfoto">Foto:</label>
<input type="file" name="cfoto">
<br>
<label for="cobserv">Observaciones:</label>
<textarea name="cobserv" cols="10" rows="3"></textarea>
<br>
<input type="submit" name="Insertarv" value="Insertar"/>
</form>
和这个PHP代码:
<?php session_start();
include("includes/conexiones.php");
$sql = "SELECT * FROM trabajos ORDER BY id DESC LIMIT 1" ;
$resultado = mysql_query($sql);
$fila = mysql_fetch_array($resultado);
$lastid = $fila["id"];
$apendice = $lastid + 1;
if ($_POST["cserv"] != "") {
$servicio=$_POST["cserv"];}
if ($_POST["cdirv"] != "") {
$direccion=$_POST["cdirv"];}
if ($_POST["cobserv"] != "") {
$observaciones=$_POST["cobserv"];}
if ($_POST["cfoto"]!=""){
$foto=$_FILES["cfoto"]["name"];
ini_set('post_max_size','100M');
ini_set('upload_max_filesize','100M');
ini_set('max_execution_time','1000');
ini_set('max_input_time','1000');
$fototmp=$_FILES["cfoto"]["tmp_name"];
list($ancho, $alto) = getimagesize($fototmp);
$nuevoancho = 600;
$nuevoalto = 600 * $alto / $ancho;
$nuevaimg = imagecreatetruecolor($nuevoancho, $nuevoalto);
$idnuevaimg = imagecreatefromjpeg($fototmp);
imagecopyresized($nuevaimg, $idnuevaimg, 0, 0, 0, 0, $nuevoancho, $nuevoalto, $ancho, $alto);
imagejpeg ($nuevaimg,"imagenes/grandes/".$prefijo.$foto);
$fototmp = $_FILES["cfoto"]["tmp_name"];
list($ancho, $alto) = getimagesize($fototmp);
$nuevoancho = 144;
$nuevoalto = 144 * $alto / $ancho;
$nuevaimg = imagecreatetruecolor($nuevoancho, $nuevoalto);
$idnuevaimg = imagecreatefromjpeg($fototmp);
imagecopyresized($nuevaimg,$idnuevaimg,0,0,0,0,$nuevoancho,$nuevoalto,$ancho,$alto);
imagejpeg ($nuevaimg,"imagenes/peques/".$prefijo.$foto);}
$nombrefoto=$apendice.$foto;
$sql="INSERT INTO trabajos (servicio, direccion, observaciones, foto) VALUES ('$servicio', '$direccion', '$observaciones', '$nombrefoto')";
mysql_query($sql);
$idtrabajo=mysql_insert_id();
header("location:insertartrabajo2.php?vid=$idtrabajo");
?>
我的问题是$foto
变量。 所有这些代码都运行了,我的计算机没有出现任何错误,但是$foto
是空的,并且在数据库“名称”列中仅显示$prefijo
变量。
问题是什么?
if ($_POST["cfoto"]!=""){ $foto=$_FILES["cfoto"]["name"];
您假设,当您提交名称为"cfoto"
的文件时,该文件将同时显示在$_FILES
和$_POST
,但不会显示。
公平地说,文档没有明确说明,但是$_POST
价值是多少? $_FILES
存在正是因为这些表单字段需要特殊处理。
检查isset($_FILES["cfoto"])
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.