1

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));
  • Yes, but this php files are just proccess, i mean if i do it for url the user has to click that url right? or the url can by ejecute it by itselt? Because my php files do not get involve with the user, so the url can´t by clicked... – Agustin Acosta Jan 07 '16 at 18:03
  • Sorry but i don't get it. The ajax code is going to be where? Is not a simple way to do this?, using, includ or require by php? – Agustin Acosta Jan 07 '16 at 18:08
  • Thats right i dont wanna by re direct to other page, i just need to pass that variable, i don´t really understand sorry, i'll think this would be easier. – Agustin Acosta Jan 07 '16 at 18:12
  • 1
    http://us3.php.net/manual/en/book.session.php – Sammitch Jan 07 '16 at 18:23
  • And how do i get the variable? or php just detect it? And another problem bro i do this include ('../imagen-ajax.php'); at top of registrar.php and the sql sentence do not execute – Agustin Acosta Jan 07 '16 at 18:29
  • Ok thank you, i take a look at it – Agustin Acosta Jan 07 '16 at 18:34
  • Possible duplicate of [PHP Pass variable to next page](http://stackoverflow.com/questions/871858/php-pass-variable-to-next-page) –  Jan 07 '16 at 18:51
  • try to work with sessions... – mikesp Apr 05 '16 at 19:49

0 Answers0