PHP - Warning: imagesx(): supplied argument is not

 
Vista:

Warning: imagesx(): supplied argument is not

Publicado por Chavex (9 intervenciones) el 25/06/2008 19:33:02
tengo un problema cuando ejecuto un codigo me da el siguienete error....

images uploaded and resized
Warning: imagesx(): supplied argument is not a valid Image resource in C:xampphtdocsUploadupload.php on line 142

Warning: Division by zero in C:xampphtdocsUploadupload.php on line 151

Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in C:xampphtdocsUploadupload.php on line 155

Warning: imagecolorstotal(): supplied argument is not a valid Image resource in C:xampphtdocsUploadupload.php on line 156

Warning: imagecopyresized(): supplied argument is not a valid Image resource in C:xampphtdocsUploadupload.php on line 162

Warning: imagejpeg(): supplied argument is not a valid Image resource in C:xampphtdocsUploadupload.php on line 163

Warning: imagedestroy(): supplied argument is not a valid Image resource in C:xampphtdocsUploadupload.php on line 164
Listing and information stored in database

elcodigo sube imagenes al servidor crea una miniatura y mete la ruta y otras informaciones en una DB

///////////////////////////////////////
CODIGO
///////////////////////////////////////

<?php
$server = "localhost";
$user = "root";
$pwd = "";

$conexion = mysql_connect ($server, $user, $pwd) or die ("NOSE HA PODI ESTABLECER CONEXION CON LA BASE DE DATOS");

mysql_select_db("upload", $conexion) or die ("NO SE PUEDE CONECTAR A LA BASE DE DATOS");
// connect to the database with your preferred method
// now lets list the variables
$mls = $_POST['mls'];
$address = $_POST['address'];
$price = $_POST['price'];
$description = $$_POST['description'];
// width and height max values for the main images. Its best to set
// them both at the same value or you will end up with distorted images
// if you upload both landscape and portrait layouts.
$width = '640';
$height = '640';
// Here we set the name and path for the thumbnails. I chose to put the thumbs
// and the main images in separate folders based on their unique MLS number.
$thumbName = "images/$mls/thumb.jpg";
// Set the thumb max width and height
$twidth = '250';
$theight = '250';

//first I want to make sure they actually posted an MLS number or we reject it
if(empty($_POST['mls']))
{
die("You didn't enter a MLS number. Please go back");
}

//now lets make sure this folder doesn't already exist so its not written over
if(file_exists("images/$mls"))
{
die("You are trying to add a listing that already exists");
}

// so far so good lets create the directory on the server and assign the filename
$oldmask = umask(0);
mkdir("images/$mls", 0777);
umask($oldmask);
$ext = '.jpg';
$fileName = "images/$mls/";

// now we will check to see if there is a file, if there is we will put it in an array
// for processing. If there is a file we are going to number them 0-5
for($i=0; $i<10; $i++)
if(!empty($_FILES["upload$i"]['name']))
{
$pic[$i] = $_FILES["upload$i"]['name'];
}

// count the total number of pictures to be resized, uploaded and stored
$totalPics = count($pic);

// now lets loop the process for each file
for($i = 0; $i<$totalPics; $i++)
// here is where you can do some file checking for example lets make sure its a .jpg.
// This would also be a good place to check the file size.
if (!eregi('^image/p?jpeg(;.*)?$', $_FILES["upload$i"]['type']))
{
// we already made the directory so lets make sure we remove it before we kill
// the script.
rmdir("images/$mls");
die("

Sorry, this was not a .jpg file

");
}
// The images met whatever conditions you set so we move forward.
else
{
if(is_uploaded_file($_FILES["upload$i"]['tmp_name']) and
copy($_FILES["upload$i"]['tmp_name'], "$fileName$i$ext"))
{
// find the dimensions
$simg = imagecreatefromjpeg("$fileName" ."$i". "$ext");
$currwidth = imagesx($simg);
$currheight = imagesy($simg);
// if its a portrait layout lets set the max height
if($currheight and $currwidth)
{
$zoom = $width/$currheight;
$newheight = $height;
$newwidth = $currwidth*$zoom;
}
// if its a landscape
else
{
$zoom = $width/$currwidth;
$newwidth = $width;
$newheight = $currheight*$zoom;
}

// Alright we have the dimensions sorted out now lets build the image. Using
// imagecreatetruecolor() instead of imagetruecolorpalette() gives us a better
// resolution
$dimg = imagecreatetruecolor($newwidth, $newheight);
$palsize = imagecolorstotal($simg);
for($e = 0; $e< $palsize; $e++)
{
$colors = imagecolorsforindex($simg, $e);
$imagecolorallocate($dimg, $colors['red'], $colors['green'], $colors['blue']);
}
imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight);
// here is where you can set the quality I set it to 90 so they end up being fairly large
imagejpeg($dimg, "$fileName" ."$i". "$ext", 90);
imagedestroy($simg);
imagedestroy($dimg);

// Round off the width and height attributes so we can store it in the database
$newheight = round($newheight);
$newwidth = round($newwidth);

// now lets add the main images to the database
$sql = "INSERT INTO images SET
filename='$fileName$i$ext',
width='$newwidth',
height='$newheight'
";

if(mysql_query($sql))
{
echo "images uploaded and resized";
}
else
{
echo "error uploading and resizing images";
}
}
}

// lets do it all again for the thumbnail images
// The first image in the upload form "upload0' will be the image we turn into a thumb.
// I added a "t" to all the thumbnail variables
if(is_uploaded_file($_FILES['upload0']['tmp_name']) and
copy($_FILES['upload0']['tmp_name'], "$thumbName"))
{
$tsimg = imagecreatefromjpeg("$thumbname");
$tcurrwidth = imagesx($tsimg);
if($tcurrheight and $tcurrwidth)
{
$tzoom = $twidth/$tcurrheight;
$tnewheight = $theight;
$tnewwidth = $tcurrwidth*$tzoom;
}
else
{
$tzoom = $twidth/$tcurrwidth;
$tnewwidth = $twidth;
$tnewheight = $tcurrheight*$tzoom;
}
$timg = imagecreatetruecolor($newwidth, $tnewheight);
$tpalsaize = imagecolorstotal($tsimg);
for($e = 0; $e<$palsize; $e++)
{
$colors = imagecolorsforindex($tsimg);
imagecolorallocate($tdimg, $colors['red'], $colors['green'], $colors['blue']);
}
imagecopyresized($tdimg, $tsimg, 0, 0, 0, 0, $tnewwidth, $tnewheight, $tcurrwidth, $tcurrheight);
imagejpeg($tdimg, $thumbName, 95);
imagedestroy($tdimg);
$tnewheight = round($tnewheight);
$tnewwidth = round($tnewwidth);
}

// now lets add the listing information and thumbnail information to the "listing" table
$sql = "INSERT INTO listing SET
mls='$mls',
address='$address',
price='$price',
description='$description',
filename='$thumbName',
width='$tnewwidth',
height='$tnewheight'
";

if(mysql_query($sql))
{
echo "Listing and information stored in database";
}
else
{
echo "Error: Listing did not store in database";
}

?>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder