Hello guys have a question, how can i pass one php variable, from a php file to another. I got imagen-ajax.php a variable call $src, and i need that value in registrar.php to save the value in a db field. How can i do this?
The code in image-ajax.php executes first, and i need a variable from this file in registrar.php.
Here is mi code imagen-ajax.php:
<?php
include 'imgcamacho.lib.php';
if (isset($_FILES["file"]))
{
$file = $_FILES["file"];
//$nombre = $file["name"];
$nombre = getUniqueName();
$tipo = $file["type"];
$ruta_provisional = $file["tmp_name"];
$size = $file["size"];
$carpeta = "upload/";
switch ($tipo) {
case 'image/jpg':
$tipo = JPG;
break;
case 'image/jpeg':
$tipo = JPEG;
break;
case 'image/png':
$tipo = PNG;
break;
case 'image/gif':
$tipo = GIF;
break;
default:
die("Error, el archivo no es una imagen");
}
$src = $carpeta.$nombre;
move_uploaded_file($ruta_provisional, $src);
changeSize($src, 500, $tipo);
echo "<img src='$src'>";
}else {
die("No se ha cargado ningún archivo");
}
Here is mi code registrar.php:
<?php
$id = $_POST['id'];
$tipo_bolsa = $_POST['tipo_bolsa'];
$titulo = $_POST['titulo'];
$imagen = $_POST['imagen'];
$descripcion = $_POST['descripcion'];
$categoria = $_POST['categoria'];
$fecha = $_POST['fecha'];
$sueldo = $_POST['sueldo'];
$idP = $_POST['idP'];
// I need imagen-ajax variable $src, to save it on image field
require('cone.php');
$con = Conectar();
$sql = 'INSERT INTO bolsa (id, tipo_bolsa, titulo, imagen, descripcion, categoria, fecha, sueldo) VALUES (:id, :tipo_bolsa, :titulo, :imagen, :descripcion, :categoria, :fecha, :sueldo)';
$q = $con->prepare($sql);
$q->execute(array(':id'=>$id, ':tipo_bolsa'=>$tipo_bolsa, ':titulo'=>$titulo, ':imagen'=>$imj, ':descripcion'=>$descripcion, ':categoria'=>$categoria, ':fecha'=>$fecha, ':sueldo'=>$sueldo));