Ver Mensaje Individual
  #1 (permalink)  
Antiguo 03/04/2013, 11:23
maquinistas
 
Fecha de Ingreso: agosto-2012
Ubicación: vigo
Mensajes: 84
Antigüedad: 10 años
Puntos: 0
Pregunta Problema Upload y Input

Buenas tardes.
Tengo un upload que sube bien las imágenes pero cuando quiero que una imagen suba con una imagen, no me aparece el nombre que le pongo en la base de datos mysql. Le he dado tantas vueltas, que ya no se qué corregir en el upload que os envío sin añadir el campo "nombre".
Agradecería vuestro esfuerzo si me podéis ayudar.

<!-- upload form -->
<a href="#x" class="overlay" id="add_form"></a>
<div class="popup">
<div class="header">
<a class="close" href="#close">Cerrar</a>
<h2>Subir Imagen</h2>
</div>
<form id="upload_form">


<input type="text" name="nombre" id="nombre"/> (Esto se lo añadí yo)

<input type="file" name="image_file" id="image_file" onchange="" />
</form>
<div id="upload_result"></div>
</div>



Y el script Upload....

function uploadImageFile() { // Note: GD library is required for this upload function

$iDefWidth = 192; // default photos width (in case of resize)
$iFDefWidth = 556; // full default photos width (in case of resize)

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$iWidth = $iHeight = $iFDefWidth; // desired image dimensions
$iJpgQuality = 75;

if ($_FILES) {

// if there are no errors and filesize less than 400kb
if (! $_FILES['image_file']['error'] && $_FILES['image_file']['size'] < 400 * 1024) {
if (is_uploaded_file($_FILES['image_file']['tmp_name'])) {

// new unique filename
$sTempFileName = 'photos/' . md5(time().rand());

// move uploaded file into cache folder
move_uploaded_file($_FILES['image_file']['tmp_name'], $sTempFileName);

// change file permission to 644
@chmod($sTempFileName, 0644);

// if temp file exists
if (file_exists($sTempFileName) && filesize($sTempFileName) > 0) {
$aSize = getimagesize($sTempFileName); // obtain image info
if (!$aSize) {
@unlink($sTempFileName);
return;
}

// check for image type and create a new image from file
switch($aSize[2]) {
case IMAGETYPE_JPEG:
$sExt = '.jpg';
$vImg = @imagecreatefromjpeg($sTempFileName);
break;
case IMAGETYPE_PNG:
$sExt = '.png';
$vImg = @imagecreatefrompng($sTempFileName);
break;
default:
@unlink($sTempFileName);
return;
}

// get source image width and height
$iSrcWidth = imagesx($vImg);
$iSrcHeight = imagesy($vImg);

// recalculate height (depends on width)
$iHeight = $iSrcHeight * $iWidth / $iSrcWidth;

// create a new true color image
$vDstImg = @imagecreatetruecolor($iWidth, $iHeight);

// copy and resize
imagecopyresampled($vDstImg, $vImg, 0, 0, 0, 0, $iWidth, $iHeight, $iSrcWidth, $iSrcHeight);

// add a blank image object into DB
$iLastId = $GLOBALS['CPhotos']->insertBlankPhoto($_FILES['image_file']['name'], $_SESSION['member_id']);

// define a result image filename
$sResultFileName = 'photos/f_pic' . $iLastId . $sExt;

// update filename for our object
$GLOBALS['CPhotos']->updateFilename($iLastId, 'pic' . $iLastId . $sExt);

// output image to file and set permission 644
imagejpeg($vDstImg, $sResultFileName, $iJpgQuality);
@chmod($sResultFileName, 0644);

// and, prepare a thumbnail as well
$iWidth = $iDefWidth;
$iHeight = $iSrcHeight * $iWidth / $iSrcWidth;
$vDstThImg = @imagecreatetruecolor($iWidth, $iHeight);
imagecopyresampled($vDstThImg, $vImg, 0, 0, 0, 0, $iWidth, $iHeight, $iSrcWidth, $iSrcHeight);
$sResultThumnName = 'photos/pic' . $iLastId . $sExt;
imagejpeg($vDstThImg, $sResultThumnName, $iJpgQuality);
@chmod($sResultThumnName, 0644);

// unlink temp file
@unlink($sTempFileName);
return $sResultFileName;
}
}
}
}
}
}

// upload available only for logged in members
if ($_SESSION['member_id'] && $_SESSION['member_status'] == 'active' && $_SESSION['member_role']) {
$sImage = uploadImageFile();
echo '1';
}