Reputation: 5
I have this code:
<?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"];
if ($_POST["cserv"] != "") {
$servicio = $_POST["cserv"];
}
if ($_POST["cdirv"] != "") {
$direccion = $_POST["cdirv"];
}
if ($_POST["cobserv"] != "") {
$observaciones = $_POST["cobserv"];
}
if ($_POST["cfotov"] != "") {
$foto = $_FILES["cfotov"]["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["cfotov"]["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/" . $fotov . $lastid + 1);
$fototmp = $_FILES["cfotov"]["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/" . $foto . $lastid + 1);
$sql = "INSERT INTO trabajos (servicio, direccion, observaciones, foto) VALUES ('$servicio', '$direccion', '$observaciones', '$foto')";
mysql_query($sql);
$idtrabajo = mysql_insert_id();
header("location:insertartrabajo2.php?vid=$idtrabajo");
?>
The problem is in this line: imagejpeg ($nuevaimg,"imagenes/grandes/".$fotov.$lastid+1);
where "$fotov
" is the image name, "$lastid
" is the last number in my database and "+1" is to increment that last number...
But it doesn't run
What´s the right way to concatenate the variables? I know I have an error, but I can't find it
Upvotes: 0
Views: 89
Reputation: 57
Or use sprintf.
imagejpeg($nuevaimg,sprintf("imagenes/grandes/%s%d", $fotov, $lastid + 1));
Upvotes: 0
Reputation: 115
$new_id = $lastid + 1;
imagejpeg ($nuevaimg,"imagenes/grandes/{$fotov}{$new_id}");
or
$new_id = $lastid + 1;
imagejpeg ($nuevaimg,"imagenes/grandes/" . $fotov . $new_id);
or
imagejpeg ($nuevaimg,"imagenes/grandes/" . $fotov . ($lastid + 1));
Upvotes: 1