/    Sign up×
Community /Pin to ProfileBookmark

Checking my image file.

Hello all,

I have been using an upload script for a while and it has been ok
but I recently bought a new camera and my pictures wont upload ?

The camera is a Vivitar 3.2 Mega Pix. (pretty basic one)
It apears to produce jpg images.

The script rejects the image with this code:

[code=php]if(!ereg(“image”,$_FILES[‘upLoad1’][‘type’])) {
$message1 = “The file you have selected for Picture 1 is not”;
$message2 = “a recognised picture file – Please try a different file”;
require_once (“a_picts_fm.php”);
exit();
} // endif[/code]

Anyway, my question is : How can I check the file on my pc before trying to upload it ?

ALSO – my script says that the file should be less than 500KB but I can not see any such limit in the script – is this a system limit ?
and can it be increased ?

Many Thanks ?

PS the complete image upload script is below:
(Its a bit long – but thats because it processes 6 pictures)

Do you see any problem with it ?

[code=php]<?php
/*
*
* Called by section_add.php s
*/

function makeThumbnail($source, $t_ht,$N_pix_n) {
$image_info = getImageSize($source) ;

// echo print_r($image_info);

switch ($image_info[‘mime’]) {
case ‘image/gif’:
if (imagetypes() & IMG_GIF) { // not the same as IMAGETYPE
$o_im = imageCreateFromGIF($source) ;
} else {
$ermsg = ‘GIF images are not supported<br />’;
}
break;
case ‘image/jpeg’:
if (imagetypes() & IMG_JPG) {
exec(“jhead -purejpg “.$source); // cleans up jpg headers
$o_im = imageCreateFromJPEG($source) ;
} else {
$ermsg = ‘JPEG images are not supported<br />’;
}
break;
case ‘image/png’:
if (imagetypes() & IMG_PNG) {
$o_im = imageCreateFromPNG($source) ;
} else {
$ermsg = ‘PNG images are not supported<br />’;
}
break;
case ‘image/wbmp’:
if (imagetypes() & IMG_WBMP) {
$o_im = imageCreateFromWBMP($source) ;
} else {
$ermsg = ‘WBMP images are not supported<br />’;
}
break;
default:
$ermsg = $image_info[‘mime’].’ images are not supported<br />’;
break;
} // end switch

IF (!isset($ermsg)) {
$o_wd = imagesx($o_im) ;
$o_ht = imagesy($o_im) ;
// thumbnail width = target * original width / original height
$t_wd = round($t_ht * $o_wd / $o_ht) ;

if(imageistruecolor($o_im)){
$N_image = @imagecreatetruecolor($t_wd, $t_ht) or die(‘Invalid resize dimmensions’);
imageAlphaBlending($N_image, false); // this disabled so that saveAlpha can be used.
imageSaveAlpha($N_image, true);
}
else{
$N_image = @imagecreate($t_wd, $t_ht) or die(‘Invalid resize dimmensions’);
if(false !== ($trans = @imagecolorsforindex($source, imagecolortransparent($source)))){
$trans = ImageColorAllocate($N_image, $trans[‘red’], $trans[‘green’], $trans[‘blue’]);
imagefilledrectangle($N_image, 0, 0, $w – 1, $h – 1, $trans);
imagecolortransparent($N_image, $trans);
}
} // end else

// echo “<br> $t_wd, $t_ht, $o_wd, $o_ht”;

imagecopyresampled($N_image, $o_im, 0, 0, 0, 0, $t_wd, $t_ht, $o_wd, $o_ht);

// $destination = “/home/blinyky/public_html/images/$N_pix_n”;

$destination = $_SERVER[‘DOCUMENT_ROOT’].”/images/$N_pix_n”;
// $destination = ‘Dwebimages’.”\”.$N_pix_n;

// echo “<br>N_image:$N_image. – N_pix_n:$N_pix_n. – Destination: $destination.”;

imageJPEG($N_image,$destination,90);
imageDestroy($o_im);
imageDestroy($N_image);

} // end IF
return (isset($ermsg)?$ermsg:NULL);
} // End of Function

require_once(“my_functions.php”);

$hgt = 120;
$today = date(U);
$pix1_y = $pix2_y = $pix3_y = $pix4_y = $pix5_y = $pix6_y = “n”;

// Checking image in pix files.

$N_pix1 = safe_sql($_FILES[‘upLoad1’][“name”]);
$N_pix2 = safe_sql($_FILES[‘upLoad2’][“name”]);
$N_pix3 = safe_sql($_FILES[‘upLoad3’][“name”]);
$N_pix4 = safe_sql($_FILES[‘upLoad4’][“name”]);
$N_pix5 = safe_sql($_FILES[‘upLoad5’][“name”]);
$N_pix6 = safe_sql($_FILES[‘upLoad6’][“name”]);

$ad_ref = safe_sql($_POST[“ad_ref”]);
$N_city = safe_sql($_POST[“x_city”]);
$section = safe_sql($_POST[“section”]);
$N_contact = safe_sql($_POST[“x_opt_contact”]);
$N_comp = safe_sql($_POST[“x_comp”]);
$N_agent = safe_sql($_POST[“x_agent”]);
$N_pass = safe_sql($_POST[“x_pass”]);
$N_email = safe_sql($_POST[“x_email”]);
$client_status = safe_sql($_POST[“client_status”]);
$N_count = safe_sql($_POST[“x_count”]);

if($N_pix1 != “”){
if($_FILES[‘upLoad1’][‘tmp_name’] == “none”) {
$message1 = “Picture file 1 did not successfully upload” ;
$message2 = “Check the file size. Must be less than 500K”;
require_once (“a_picts_fm.php”);
exit();
} // endif

if(!ereg(“image”,$_FILES[‘upLoad1’][‘type’])) {
$message1 = “The file you have selected for Picture 1 is not”;
$message2 = “a recognised picture file – Please try a different file”;
require_once (“a_picts_fm.php”);
exit();
} // endif
$pix1_y = “y”;
} // endif
else{
$N_pix1 = “none”;
} // end else

// AND THEN REPEAT SIX TIMES

/*
* Everything seems ok – so we create the thumbnails from the temp_files.
*/

if($pix1_y == “y”){
$image = $_FILES[‘upLoad1’][‘tmp_name’];
$N_pix1 = time().”-“.$N_pix1;
makeThumbnail($image,$hgt,$N_pix1);
} // endif

if($pix2_y == “y”){
$N_pix2 = time().”-“.$N_pix2;
$image = $_FILES[‘upLoad2’][‘tmp_name’];
makeThumbnail($image,$hgt,$N_pix2);
} // endif

if($pix3_y == “y”){
$N_pix3 = time().”-“.$N_pix3;
$image = $_FILES[‘upLoad3’][‘tmp_name’];
makeThumbnail($image,$hgt,$N_pix3);
} // endif

if($pix4_y == “y”){
$N_pix4 = time().”-“.$N_pix4;
$image = $_FILES[‘upLoad4’][‘tmp_name’];
makeThumbnail($image,$hgt,$N_pix4);
} // endif

if($pix5_y == “y”){
$N_pix5 = time().”-“.$N_pix5;
$image = $_FILES[‘upLoad5’][‘tmp_name’];
makeThumbnail($image,$hgt,$N_pix5);
} // endif

if($pix6_y == “y”){
$N_pix6 = time().”-“.$N_pix6;
$image = $_FILES[‘upLoad6’][‘tmp_name’];
makeThumbnail($image,$hgt,$N_pix6);
} // endif

/*
* Update the ADVERT WITH THE IMAGE NAMES
*/

// echo “adref: $ad_ref .”;

require_once(“Letter_yod.inc”);
$connection = mysql_connect($host,$user,$password)
or die (“Couldn’t connect to server.”);

$db = mysql_select_db($database, $connection)
or die (“Couldn’t select database.”);

$sql = “UPDATE $section SET
image1 = ‘$N_pix1’,
image2 = ‘$N_pix2’,
image3 = ‘$N_pix3’,
image4 = ‘$N_pix4’,
image5 = ‘$N_pix5’,
image6 = ‘$N_pix6’

WHERE ad_ref = ‘$ad_ref’ “;

mysql_query($sql)
or die(“could not execute $section UPDATE PICTURES query”);

// echo ” <br> client_status: $client_status:”;

/*
* Update the client table – WE DO THIS BECAUSE THE WITH PICTS ADVERTS SKIPPED THIS.
*/

if($client_status == “c”){ // IF THEY ARE A CONFIRMED CLIENT
$N_count = $N_count + 1;

$sql = “UPDATE clients SET
contact = ‘$N_contact’,
last_date = ‘$today’,
count = ‘$N_count’,
posted = ‘$section’

WHERE email = ‘$N_email’ “;

mysql_query($sql)
or die(“could not execute CLIENTS ($section) UPDATE query”);

/*
* send THANK YOU email
*/
$prog_tp = “add”;
$prog = $section.”_add.php”;
$go_prog = $section.”_disp.php”;
require_once(“$go_prog”);
exit();

} // endif

/*
* Add a New client to the table
*/

if($client_status == “N”){ // IF THEY ARE A NEW CLIENT
$mess1 = “”;
$N_count = 1;

/* ********* TEST DISPLAY ************

echo” <br />
************<br />

city: $N_city<br />
confirm: $N_confirm<br />
count: $N_count<br />
contact: $N_contact<br />
comp: $N_comp<br />
agent: $N_agent<br />
email: $N_email<br />
pass: $N_pass<br />
create_date: $today<br />
“;
*/

$sql = “INSERT INTO clients (confirm,comp,agent,city,count,contact,email,pass,create_date,last_date,posted)

VALUES (‘$N_confirm’,’$N_comp’,’$N_agent’,’$N_city’,’$N_count’,’$N_contact’,’$N_email’,’$N_pass’,
‘$today’,’$today’,’$section’)”;

mysql_query($sql)
or die(“could not execute CLIENT INSERT query – $section”);

/*
* send ACTIVATION email
*/

require_once(“b_email_act.php”);

$prog_tp = “add”;
$prog = $section.”_add.php”;
$go_prog = $section.”_disp.php”;
require_once(“$go_prog”);
exit();
} // endif
?>[/code]

to post a comment
PHP

43 Comments(s)

Copy linkTweet thisAlerts:
@DaveinLondonauthorNov 02.2006 — Maybe my question wasn't written very well -

so I have explained it again here:

The error that I was getting when using my upload script was:

"The file you have selected for Picture 1 is not

a recognised picture file - Please try a different file"

i.e. it was rejected by the bit of the code that I highlighted.

So my two questions were

1) how can I check my image file to see if it will get thrown out by that bit of code:

if(!ereg("image",$_FILES['upLoad1']['type'])) { reject it }

and a seperate question

2) since the other reject reason is dealt by this bit of script:

[code=php]if($_FILES['upLoad1']['tmp_name'] == "none") {
$message1 = "Picture file 1 did not successfully upload" ;
$message2 = "Check the file size. Must be less than 500K";
require_once ("a_picts_fm.php");
exit();
} // endif [/code]


where in my script does it specify a 500k limit ?

Why should a tmp_name = none mean that the file was over 500K ? ?

I hope this helps to clarify my problem and if you can see where I've gone wrong, I'll much appreciate your guidance ?

Full code here:

Please let me know what you think is wrong.

[code=php]<?php

/*
*
* Called by section_add.php s
*/

function makeThumbnail($source, $t_ht,$N_pix_n) {
$image_info = getImageSize($source) ;

// echo print_r($image_info);

switch ($image_info['mime']) {
case 'image/gif':
if (imagetypes() & IMG_GIF) { // not the same as IMAGETYPE
$o_im = imageCreateFromGIF($source) ;
} else {
$ermsg = 'GIF images are not supported<br />';
}
break;
case 'image/jpeg':
if (imagetypes() & IMG_JPG) {
exec("jhead -purejpg ".$source); // cleans up jpg headers
$o_im = imageCreateFromJPEG($source) ;
} else {
$ermsg = 'JPEG images are not supported<br />';
}
break;
case 'image/png':
if (imagetypes() & IMG_PNG) {
$o_im = imageCreateFromPNG($source) ;
} else {
$ermsg = 'PNG images are not supported<br />';
}
break;
case 'image/wbmp':
if (imagetypes() & IMG_WBMP) {
$o_im = imageCreateFromWBMP($source) ;
} else {
$ermsg = 'WBMP images are not supported<br />';
}
break;
default:
$ermsg = $image_info['mime'].' images are not supported<br />';
break;
} // end switch

IF (!isset($ermsg)) {
$o_wd = imagesx($o_im) ;
$o_ht = imagesy($o_im) ;
// thumbnail width = target * original width / original height
$t_wd = round($t_ht * $o_wd / $o_ht) ;

if(imageistruecolor($o_im)){
$N_image = @imagecreatetruecolor($t_wd, $t_ht) or die('Invalid resize dimmensions');
imageAlphaBlending($N_image, false); // this disabled so that saveAlpha can be used.
imageSaveAlpha($N_image, true);
}
else{
$N_image = @imagecreate($t_wd, $t_ht) or die('Invalid resize dimmensions');
if(false !== ($trans = @imagecolorsforindex($source, imagecolortransparent($source)))){
$trans = ImageColorAllocate($N_image, $trans['red'], $trans['green'], $trans['blue']);
imagefilledrectangle($N_image, 0, 0, $w - 1, $h - 1, $trans);
imagecolortransparent($N_image, $trans);
}
} // end else

// echo "<br> $t_wd, $t_ht, $o_wd, $o_ht";

imagecopyresampled($N_image, $o_im, 0, 0, 0, 0, $t_wd, $t_ht, $o_wd, $o_ht);

// $destination = "/home/blinyky/public_html/images/$N_pix_n";

$destination = $_SERVER['DOCUMENT_ROOT']."/images/$N_pix_n";
// $destination = 'Dwebimages'."\".$N_pix_n;

// echo "<br>N_image:$N_image. - N_pix_n:$N_pix_n. - Destination: $destination.";

imageJPEG($N_image,$destination,90);
imageDestroy($o_im);
imageDestroy($N_image);

} // end IF
return (isset($ermsg)?$ermsg:NULL);
} // End of Function

require_once("my_functions.php");

$hgt = 120;
$today = date(U);
$pix1_y = $pix2_y = $pix3_y = $pix4_y = $pix5_y = $pix6_y = "n";

// Checking image in pix files.

$N_pix1 = safe_sql($_FILES['upLoad1']["name"]);
$N_pix2 = safe_sql($_FILES['upLoad2']["name"]);
$N_pix3 = safe_sql($_FILES['upLoad3']["name"]);
$N_pix4 = safe_sql($_FILES['upLoad4']["name"]);
$N_pix5 = safe_sql($_FILES['upLoad5']["name"]);
$N_pix6 = safe_sql($_FILES['upLoad6']["name"]);

$ad_ref = safe_sql($_POST["ad_ref"]);
$N_city = safe_sql($_POST["x_city"]);
$section = safe_sql($_POST["section"]);
$N_contact = safe_sql($_POST["x_opt_contact"]);
$N_comp = safe_sql($_POST["x_comp"]);
$N_agent = safe_sql($_POST["x_agent"]);
$N_pass = safe_sql($_POST["x_pass"]);
$N_email = safe_sql($_POST["x_email"]);
$client_status = safe_sql($_POST["client_status"]);
$N_count = safe_sql($_POST["x_count"]);

if($N_pix1 != ""){
if($_FILES['upLoad1']['tmp_name'] == "none") {
$message1 = "Picture file 1 did not successfully upload" ;
$message2 = "Check the file size. Must be less than 500K";
require_once ("a_picts_fm.php");
exit();
} // endif

if(!ereg("image",$_FILES['upLoad1']['type'])) {
$message1 = "The file you have selected for Picture 1 is not";
$message2 = "a recognised picture file - Please try a different file";
require_once ("a_picts_fm.php");
exit();
} // endif
$pix1_y = "y";
} // endif
else{
$N_pix1 = "none";
} // end else

// AND THEN REPEAT ANOTHER FIVE TIMES

/*
* Everything seems ok - so we create the thumbnails from the temp_files.
*/

if($pix1_y == "y"){
$image = $_FILES['upLoad1']['tmp_name'];
$N_pix1 = time()."-".$N_pix1;
makeThumbnail($image,$hgt,$N_pix1);
} // endif

// AND THEN REPEAT ANOTHER FIVE TIMES

/*
* Update the ADVERT WITH THE IMAGE NAMES
*/

// echo "adref: $ad_ref .";

require_once("Letter_yod.inc");
$connection = mysql_connect($host,$user,$password)
or die ("Couldn't connect to server.");

$db = mysql_select_db($database, $connection)
or die ("Couldn't select database.");


$sql = "UPDATE $section SET
image1 = '$N_pix1',
image2 = '$N_pix2',
image3 = '$N_pix3',
image4 = '$N_pix4',
image5 = '$N_pix5',
image6 = '$N_pix6'

WHERE ad_ref = '$ad_ref' ";

mysql_query($sql)
or die("could not execute $section UPDATE PICTURES query");

// echo " <br> client_status: $client_status:";

/*
* Update the client table - WE DO THIS BECAUSE THE WITH PICTS ADVERTS SKIPPED THIS.
*/

if($client_status == "c"){ // IF THEY ARE A CONFIRMED CLIENT
$N_count = $N_count + 1;

$sql = "UPDATE clients SET
contact = '$N_contact',
last_date = '$today',
count = '$N_count',
posted = '$section'

WHERE email = '$N_email' ";

mysql_query($sql)
or die("could not execute CLIENTS ($section) UPDATE query");

/*
* send THANK YOU email

*/
$prog_tp = "add";
$prog = $section."_add.php";
$go_prog = $section."_disp.php";
require_once("$go_prog");
exit();

} // endif

/*
* Add a New client to the table
*/

if($client_status == "N"){ // IF THEY ARE A NEW CLIENT
$mess1 = "";
$N_count = 1;

$sql = "INSERT INTO clients (confirm,comp,agent,city,count,contact,email,pass,create_date,last_date,posted)

VALUES ('$N_confirm','$N_comp','$N_agent','$N_city','$N_count','$N_contact','$N_email','$N_pass',
'$today','$today','$section')";

mysql_query($sql)
or die("could not execute CLIENT INSERT query - $section");

/*
* send ACTIVATION email
*/

require_once("b_email_act.php");

$prog_tp = "add";
$prog = $section."_add.php";
$go_prog = $section."_disp.php";
require_once("$go_prog");
exit();
} // endif
?> [/code]
Copy linkTweet thisAlerts:
@so_is_thisNov 02.2006 — where in my script does it specify a 500k limit ?

Why should a tmp_name = none mean that the file was over 500K ? ?[/QUOTE]

...tmp_name... == "none" means that PHP dropped (didn't save with a temporary name) the uploaded file.
Copy linkTweet thisAlerts:
@so_is_thisNov 02.2006 — how can I check my image file to see if it will get thrown out by that bit of code:

if(!ereg("image",$_FILES['upLoad1']['type'])) { reject it }[/QUOTE]

Right before that statement, do this:

echo $_FILES['upLoad1']['type'];

to see what Content-type is assigned to that file.
Copy linkTweet thisAlerts:
@DaveinLondonauthorNov 03.2006 — Thanks for your input.

I changed the MAX FILE to:

<input type="hidden" name ="MAX FILE SIZE" value="1000000">

and the error message now read:

[code=php]if($_FILES['upLoad1']['tmp_name'] == "none") {
$message1 = "Picture file 1 did not successfully upload" ;
$message2 = "Check the file size. Must be less than 1MB";
require_once ("a_picts_fm.php");
exit();
} // endif

if(!ereg("image",$_FILES['upLoad1']['type'])) {
$message1 = "The file you have selected for Picture 1 is not a recognised picture file.";
$message2 = "Type = ".$_FILES['upLoad1']['type'];
require_once ("a_picts_fm.php");
exit();
} // endif[/code]



Now the strange thing is - these " error if " s don't catch anything.

Everything appears ok but when the makeThumbnail() runs I get errors:

Warning: imagecreatefromjpeg(): '/tmp/phpZwctij' is not a valid JPEG file in /a_pic_updater.php on line 23

Warning: imagesx(): supplied argument is not a valid Image resource in /a_pic_updater.php on line 48

Warning: imagesy(): supplied argument is not a valid Image resource in /a_pic_updater.php on line 49

Warning: Division by zero in /a_pic_updater.php on line 51

Warning: imageistruecolor(): supplied argument is not a valid Image resource in /a_pic_updater.php on line 53

Invalid resize dimmensions

ALL of these are obviously due to an invalid image file.

This is the part of the function that gives the problem:

case 'image/jpeg':
if (imagetypes() & IMG_JPG) {
exec("jhead -purejpg ".$source); // cleans up jpg headers
$o_im = imageCreateFromJPEG($source) ;
} else {
$ermsg = 'JPEG images are not supported<br />';
}


I have tried the function with this line :

exec("jhead -purejpg ".$source); // cleans up jpg headers

in AND with it commented out - but I get the same errors.

I don't know where the name '/tmp/phpZwctij' comes from !

The file I upload is named: IMAG0009.JPG

Any sugestions on what is going wrong ?
Copy linkTweet thisAlerts:
@so_is_thisNov 03.2006 — Thanks for your input.

I changed the MAX FILE to:

<input type="hidden" name ="MAX FILE SIZE" value="1000000">[/QUOTE]


One meg is 1048576 bytes. ?
Copy linkTweet thisAlerts:
@DaveinLondonauthorNov 03.2006 — BTW I also added this line :

echo "File type: ".$_FILES['upLoad1']['type']." <br>";

and the output is now:

File type: image/jpeg

Warning: imagecreatefromjpeg(): '/tmp/phpYVfkf6' is not a valid JPEG file in /a_pic_updater.php on line 23

Warning: imagesx(): supplied argument is not a valid Image resource in /a_pic_updater.php on line 48

Warning: imagesy(): supplied argument is not a valid Image resource in /a_pic_updater.php on line 49

Warning: Division by zero in /a_pic_updater.php on line 51

Warning: imageistruecolor(): supplied argument is not a valid Image resource in /a_pic_updater.php on line 53

Invalid resize dimmensions

So the file type is the expected image/jpeg and as it is under a 1MB I would expect it to pass the to if statements - but why does this line fail ?

$o_im = imageCreateFromJPEG($source) ;

Please help - as I have no idea how to check the file or what to do with it. ?

The exec("jhead -purejpg ".$source); is supposed to clean up the file - but maybe it does NOT do the job ???

Any thoughts ??
Copy linkTweet thisAlerts:
@so_is_thisNov 03.2006 — I don't know where the name '/tmp/phpZwctij' comes from !

The file I upload is named: IMAG0009.JPG

Any sugestions on what is going wrong ?[/QUOTE]

PHP generates a temporary file name, for each file uploaded, and places that file in a temporary folder. It looks like that is what you're seeing. As for the error messages -- sorry, I don't have any immediate answers for you.
Copy linkTweet thisAlerts:
@bokehNov 03.2006 — One meg is 1048576 bytes. ?[/QUOTE]Not if you follow ISO standards.
Copy linkTweet thisAlerts:
@bokehNov 03.2006 — DaveinLondon, none of these methods you are using are very safe. Check out the upload tutorial stuck at the top of the forum. In particular, use of [I]getimagesize[/I] to test for images and use of [I]$_FILES[$fieldname]['error'][/I] to check the upload status.
Copy linkTweet thisAlerts:
@DaveinLondonauthorNov 04.2006 — H&#305; Boker

Thanks for your reply.

When I first wrote my upload script I did go through the tute that you posted and tried to incorparate what I understood :o

I think that I have used the "getimagesize" in my function to check for the image - the first line.

But it is used to define $image_info

- maybe I should have use it in an if stmt first ?

Here is the function again :


[code=php]function makeThumbnail($source, $t_ht,$N_pix_n) {

$image_info = getImageSize($source) ;

echo print_r($image_info);

switch ($image_info['mime']) {
case 'image/gif':
if (imagetypes() & IMG_GIF) { // not the same as IMAGETYPE
$o_im = imageCreateFromGIF($source) ;
} else {
$ermsg = 'GIF images are not supported<br />';
}
break;
case 'image/jpeg':
if (imagetypes() & IMG_JPG) {
exec("jhead -purejpg ".$source); // cleans up jpg headers
$o_im = imageCreateFromJPEG($source) ;
} else {
$ermsg = 'JPEG images are not supported<br />';
}
break;
case 'image/png':
if (imagetypes() & IMG_PNG) {
$o_im = imageCreateFromPNG($source) ;
} else {
$ermsg = 'PNG images are not supported<br />';
}
break;
case 'image/wbmp':
if (imagetypes() & IMG_WBMP) {
$o_im = imageCreateFromWBMP($source) ;
} else {
$ermsg = 'WBMP images are not supported<br />';
}
break;
default:
$ermsg = $image_info['mime'].' images are not supported<br />';
break;
} // end switch

IF (!isset($ermsg)) {
$o_wd = imagesx($o_im) ;
$o_ht = imagesy($o_im) ;
// thumbnail width = target * original width / original height
$t_wd = round($t_ht * $o_wd / $o_ht) ;

if(imageistruecolor($o_im)){
$N_image = @imagecreatetruecolor($t_wd, $t_ht) or die('Invalid resize dimmensions');
imageAlphaBlending($N_image, false); // this disabled so that saveAlpha can be used.
imageSaveAlpha($N_image, true);
}
else{
$N_image = @imagecreate($t_wd, $t_ht) or die('Invalid resize dimmensions');
if(false !== ($trans = @imagecolorsforindex($source, imagecolortransparent($source)))){
$trans = ImageColorAllocate($N_image, $trans['red'], $trans['green'], $trans['blue']);
imagefilledrectangle($N_image, 0, 0, $w - 1, $h - 1, $trans);
imagecolortransparent($N_image, $trans);
}
} // end else

// echo "<br> $t_wd, $t_ht, $o_wd, $o_ht";

imagecopyresampled($N_image, $o_im, 0, 0, 0, 0, $t_wd, $t_ht, $o_wd, $o_ht);

// $destination = "/home/blinyky/public_html/images/$N_pix_n";

$destination = $_SERVER['DOCUMENT_ROOT']."/images/$N_pix_n";
// $destination = 'Dwebimages'."\".$N_pix_n;

// echo "<br>N_image:$N_image. - N_pix_n:$N_pix_n. - Destination: $destination.";

imageJPEG($N_image,$destination,90);
imageDestroy($o_im);
imageDestroy($N_image);

} // end IF
return (isset($ermsg)?$ermsg:NULL);
} // End of Function [/code]


SECONDLY

I am not sure how to incorparate this error array into my script.

The bit I am unsure about is using the "or" in here:

($_FILES['upLoad1']['error'] == 0)

or error($errors[$_
FILES['upLoad1']['error']], $uploadForm); [/QUOTE]


I have converted it to an "if" stmt so I can be similar to my other error "ifs" . Is this doing what you recommended

I would appreciate some help ? Thanks

From my script:

[code=php]// possible PHP upload errors
$errors = array(1 => 'php.ini max file size exceeded',
2 => 'html form max file size exceeded',
3 => 'file upload was only partial',
4 => 'no file was attached');

if($N_pix1 != ""){

echo "File type: ".$_FILES['upLoad1']['type']." <br>"; // this is a temporary test

if ($_FILES['upLoad1']['error'] != 0) {
$message1 = "Picture file 1 did not successfully upload" ;
$message2 = "Error: ".$errors[$_FILES['upLoad1']['error']];
require_once ("a_picts_fm.php");
exit();
} // endif

if($_FILES['upLoad1']['tmp_name'] == "none") {
$message1 = "Picture file 1 did not successfully upload" ;
$message2 = "Check the file size. Must be less than 1MB";
require_once ("a_picts_fm.php");
exit();
} // endif

if(!ereg("image",$_FILES['upLoad1']['type'])) {
$message1 = "The file you have selected for Picture 1 is not a recognised picture file.";
$message2 = "Type = ".$_FILES['upLoad1']['type'];
require_once ("a_picts_fm.php");
exit();
} // endif
$pix1_y = "y";
} // endif
else{
$N_pix1 = "none";
} // end else[/code]
Copy linkTweet thisAlerts:
@bokehNov 04.2006 — Where did you get this code? Why is it so complicated? Why are you using a bitwise [I]and[/I]?
Copy linkTweet thisAlerts:
@DaveinLondonauthorNov 04.2006 — Hi Bokeh ( sorry mis-spelt it earlier )

Where did you get this code? [/QUOTE]

Various places - but I put the bits together to do what I need because I have a specific job to do - see below.

Why is it so complicated? [/QUOTE]

Because it is dealing with 6 files of unknown format: gif, jpg. png etc.

and because I am not just uploading a file - I am creating and saving a thumbnail version of the file. ( I don't save the uploaded file. )

Also - I am a newbie and I don't understand it all yet :o

And thats the reason for being here ?

Why are you using a bitwise and?[/QUOTE]

Are you refering to this ?
[code=php]if (imagetypes() & IMG_JPG) [/code]

Answer : I don't know

  • - how should I be writing it ?


  • - how should I be using the "getimagesize()" to check the file ?


  • - Is my if stmt doing what you recommended ?


  • [code=php] if ($_FILES['upLoad1']['error'] != 0) {
    $message1 = "Picture file 1 did not successfully upload" ;
    $message2 = "Error: ".$errors[$_FILES['upLoad1']['error']];
    require_once ("a_picts_fm.php");
    exit();
    } // endif [/code]


    Would really appreciate some more help. ?

    Many thanks.
    Copy linkTweet thisAlerts:
    @so_is_thisNov 04.2006 — Are you refering to this ?
    [code=php]if (imagetypes() & IMG_JPG) [/code]

    Answer : I don't know

  • - how should I be writing it ?
  • [/QUOTE]

    Just as you want == for "equals", then you want || for "or" and && for "and" -- as logical comparison operators.
    Copy linkTweet thisAlerts:
    @bokehNov 04.2006 — Because it is dealing with 6 files of unknown format[/QUOTE]Sorry, but I can't see the dynamic mechanism in the code that deals with multiple files. Still seems complicated. For example why do you check what files your version of PHP is compatible with each time you process a file? Surely you must know this in advance. Obviously it would be different if the script were for public download.

    What happens if one of your file fields is empty? How do you handle that?Are you refering to this ?[/QUOTE]It should be written "[I]and[/I]" or "[I]&&[/I]"

    I wrote a [URL=http://nicolas-y-sofia.moralet.com/]gallery script[/URL] the other day for my missis and it seems a lot simpler than this one.
    Copy linkTweet thisAlerts:
    @DaveinLondonauthorNov 05.2006 — OK - as I said, I am here to learn and yes I DO want to make it less complicated if possible.

    I appreciate your help and would really like to get it sorted out ?

    SO lets start with this php compatiblity check.

    1)

    The server I use is running PHP version 4.4.2

    Do you know what image types that it supports ?

    If so - I am very happy to take out that checking routine.

    However - don't I still need that switch/case routine in order to decide which imagecreatefromXXX() function to use ?

    2)
    What happens if one of your file fields is empty? How do you handle that?[/QUOTE]
    I beleive that the if stmt (see below) deals with that - there is an if for each of the six image places. If it is blank, it is skipped.

    3) Thanks for the && advice - I have changed the switch loop to:

    [code=php]switch ($image_info['mime']) {
    case 'image/gif':
    if (imagetypes() && IMG_GIF) { // not the same as IMAGETYPE
    $o_im = imageCreateFromGIF($source) ;
    } else {
    $ermsg = 'GIF images are not supported<br />';
    }
    break;
    case 'image/jpeg':
    if (imagetypes() && IMG_JPG) {
    exec("jhead -purejpg ".$source); // cleans up jpg headers
    $o_im = imageCreateFromJPEG($source) ;
    } else {
    $ermsg = 'JPEG images are not supported<br />';
    }
    break;
    case 'image/png':
    if (imagetypes() && IMG_PNG) {
    $o_im = imageCreateFromPNG($source) ;
    } else {
    $ermsg = 'PNG images are not supported<br />';
    }
    break;
    case 'image/wbmp':
    if (imagetypes() && IMG_WBMP) {
    $o_im = imageCreateFromWBMP($source) ;
    } else {
    $ermsg = 'WBMP images are not supported<br />';
    }
    break;
    default:
    $ermsg = $image_info['mime'].' images are not supported<br />';
    break;
    } // end switch
    [/code]


    Is that correct now ?


    4) You didn't answer this:

  • - how should I be using the "getimagesize()" to check the file ?


  • 5) or this ( I am trying to implement what you recommended)

  • - Is my if stmt doing what you recommended ?


  • [code=php]// possible PHP upload errors
    $errors = array(1 => 'php.ini max file size exceeded',
    2 => 'html form max file size exceeded',
    3 => 'file upload was only partial',
    4 => 'no file was attached');

    if($N_pix1 != ""){ // This is one of S&#304;X ifs. If the field is blank it is skipped.

    echo "File type: ".$_FILES['upLoad1']['type']." <br>"; // this is a temporary test

    if ($_FILES['upLoad1']['error'] != 0) {
    $message1 = "Picture file 1 did not successfully upload" ;
    $message2 = "Error: ".$errors[$_FILES['upLoad1']['error']];
    require_once ("a_picts_fm.php");
    exit();
    } // endif

    if($_FILES['upLoad1']['tmp_name'] == "none") {
    $message1 = "Picture file 1 did not successfully upload" ;
    $message2 = "Check the file size. Must be less than 1MB";
    require_once ("a_picts_fm.php");
    exit();
    } // endif

    if(!ereg("image",$_FILES['upLoad1']['type'])) {
    $message1 = "The file you have selected for Picture 1 is not a recognised picture file.";
    $message2 = "Type = ".$_FILES['upLoad1']['type'];
    require_once ("a_picts_fm.php");
    exit();
    } // endif
    $pix1_y = "y";
    } // endif
    else{
    $N_pix1 = "none";
    } // end else [/code]
    Copy linkTweet thisAlerts:
    @bokehNov 05.2006 — Lets start again from scratch. You don't need a switch statement at all. What exactly does the script store? Just a thumbnail image and nothing else? Or a resized image and a thumbnail?
    Copy linkTweet thisAlerts:
    @DaveinLondonauthorNov 05.2006 — What exactly does the script store?

    Just a thumbnail image and nothing else?

    Or a resized image and a thumbnail?[/QUOTE]


    I thought a thumbnail was a resized image ??? ?

    Please look at the script, maybe you can tell me whether its a thumbnail or something else.

    Here is my script (again) but - have added extra comments to aid understanding.

    I'll appreciate more gu&#305;dance ?

    Thanks.

    [code=php]<?php
    /*
    * THIS SCRIPT IS CALLED BY THE SUBMIT BUTTON ON THE FORM
    */


    // THIS FUNCTION IS CALLED IN THE PHP SCRIPT BELOW.

    function makeThumbnail($source, $t_ht,$N_pix_n) {

    $image_info = getImageSize($source) ;

    // echo print_r($image_info);


    // the images are uploaded by members of the public - so I do not know what format they will be - I would like to accept as many as possible.

    // switch - selecting which imageCreateFrom() to use

    switch ($image_info['mime']) {
    case 'image/gif':
    if (imagetypes() && IMG_GIF) { // not the same as IMAGETYPE
    $o_im = imageCreateFromGIF($source) ;
    } else {
    $ermsg = 'GIF images are not supported<br />';
    }
    break;
    case 'image/jpeg':
    if (imagetypes() && IMG_JPG) {
    exec("jhead -purejpg ".$source); // cleans up jpg headers
    $o_im = imageCreateFromJPEG($source) ;
    } else {
    $ermsg = 'JPEG images are not supported<br />';
    }
    break;
    case 'image/png':
    if (imagetypes() && IMG_PNG) {
    $o_im = imageCreateFromPNG($source) ;
    } else {
    $ermsg = 'PNG images are not supported<br />';
    }
    break;
    case 'image/wbmp':
    if (imagetypes() && IMG_WBMP) {
    $o_im = imageCreateFromWBMP($source) ;
    } else {
    $ermsg = 'WBMP images are not supported<br />';
    }
    break;
    default:
    $ermsg = $image_info['mime'].' images are not supported<br />';
    break;
    } // end switch

    // if no error - calculate the sizes
    // then creates true color image or normal one

    IF (!isset($ermsg)) {
    $o_wd = imagesx($o_im) ;
    $o_ht = imagesy($o_im) ;
    // thumbnail width = target * original width / original height
    $t_wd = round($t_ht * $o_wd / $o_ht) ;

    if(imageistruecolor($o_im)){
    $N_image = @imagecreatetruecolor($t_wd, $t_ht) or die('Invalid resize dimmensions');
    imageAlphaBlending($N_image, false); // this disabled so that saveAlpha can be used.
    imageSaveAlpha($N_image, true);
    }

    else{
    $N_image = @imagecreate($t_wd, $t_ht) or die('Invalid resize dimmensions');
    if(false !== ($trans = @imagecolorsforindex($source, imagecolortransparent($source)))){
    $trans = ImageColorAllocate($N_image, $trans['red'], $trans['green'], $trans['blue']);
    imagefilledrectangle($N_image, 0, 0, $w - 1, $h - 1, $trans);
    imagecolortransparent($N_image, $trans);
    }
    } // end else

    // test
    // echo "<br> $t_wd, $t_ht, $o_wd, $o_ht";

    imagecopyresampled($N_image, $o_im, 0, 0, 0, 0, $t_wd, $t_ht, $o_wd, $o_ht);


    $destination = $_SERVER['DOCUMENT_ROOT']."/images/$N_pix_n";

    // test

    // echo "<br>N_image:$N_image. - N_pix_n:$N_pix_n. - Destination: $destination.";


    // create the jpeg image AND SAVE IT AT THE DESTINATION

    imageJPEG($N_image,$destination,90);
    imageDestroy($o_im);
    imageDestroy($N_image);

    } // end IF

    return (isset($ermsg)?$ermsg:NULL);


    } // END OF FUNCTION



    // ------------------------ NOW HERE IS THE MAIN SCRIPT ----------------

    require_once("my_functions.php"); // just contains the safe_sql()

    // SPECIFY THE HIEGHT OF THE THUMBNAIL (OR "RESIZED IMAGE") THAT I WANT TO CREATE
    $hgt = 120;

    // USED TO CREATE UNIQUE FILE NAME
    $today = date(U);

    // INITIATES VALUES
    $pix1_y = $pix2_y = $pix3_y = $pix4_y = $pix5_y = $pix6_y = "n";

    // Get the SIX file names from the form.

    $N_pix1 = safe_sql($_FILES['upLoad1']["name"]);
    $N_pix2 = safe_sql($_FILES['upLoad2']["name"]);
    $N_pix3 = safe_sql($_FILES['upLoad3']["name"]);
    $N_pix4 = safe_sql($_FILES['upLoad4']["name"]);
    $N_pix5 = safe_sql($_FILES['upLoad5']["name"]);
    $N_pix6 = safe_sql($_FILES['upLoad6']["name"]);

    // recommended checking.

    // possible PHP upload errors
    $errors = array(1 => 'php.ini max file size exceeded',
    2 => 'html form max file size exceeded',
    3 => 'file upload was only partial',
    4 => 'no file was attached');

    if($N_pix1 != ""){
    echo "File type: ".$_FILES['upLoad1']['type']." <br>"; // this is a temporary test

    if ($_FILES['upLoad1']['error'] != 0) {
    $message1 = "Picture file 1 did not successfully upload" ;
    $message2 = "Error: ".$errors[$_FILES['upLoad1']['error']];
    require_once ("a_picts_fm.php");
    exit();
    } // endif

    if($_FILES['upLoad1']['tmp_name'] == "none") {
    $message1 = "Picture file 1 did not successfully upload" ;
    $message2 = "Check the file size. Must be less than 1MB";
    require_once ("a_picts_fm.php");
    exit();
    } // endif

    if(!ereg("image",$_FILES['upLoad1']['type'])) {
    $message1 = "The file you have selected for Picture 1 is not a recognised picture file.";
    $message2 = "Type = ".$_FILES['upLoad1']['type'];
    require_once ("a_picts_fm.php");
    exit();
    } // endif
    $pix1_y = "y";
    } // endif
    else{
    $N_pix1 = "none";
    } // end else

    //------------------------

    THIS IS THEN REPEATED ANOTHER FIVE TIMES
    SO THAT ALL SIX IMAGES ARE CHECKED.

    //------------------------

    /*
    * Everything seems ok - so we create the thumbnails from the temp_files.
    */

    if($pix1_y == "y"){ // ONLY IF THERE IS A FILE DO WE CALL THE FUNCTION
    $image = $_FILES['upLoad1']['tmp_name'];
    $N_pix1 = time()."-".$N_pix1; // CREATE A UNIQUE NAME
    makeThumbnail($image,$hgt,$N_pix1); // RUN THE FUNCTION ( SEE ABOVE )
    } // endif


    //------------------------

    THIS IS THEN REPEATED ANOTHER FIVE TIMES
    SO THAT ALL SIX IMAGES ARE CHECKED AND THE IMAGES ARE CREATED

    //------------------------


    /*
    * Update the ADVERT WITH THE IMAGE NAMES
    */

    // CONNECT AND UPDATE DB

    CONNECT

    $sql = "UPDATE $section SET
    image1 = '$N_pix1',
    image2 = '$N_pix2',
    image3 = '$N_pix3',
    image4 = '$N_pix4',
    image5 = '$N_pix5',
    image6 = '$N_pix6'

    WHERE ad_ref = '$ad_ref' ";

    mysql_query($sql)
    or die("could not execute $section UPDATE PICTURES query");


    // SO NOW ALL THE IMAGES ARE STORED
    // AND THE IMAGE FILES NAMES HAVE BEEN WRITTEN TO THE DB.
    // JOB DONE :)

    // RETURN TO MAIN SCRIPT

    require_once("MAIN-SCRIPT");
    Exit();
    ?>[/code]
    Copy linkTweet thisAlerts:
    @bokehNov 05.2006 — [code=php]if($N_pix1 != ""){
    echo "File type: ".$_FILES['upLoad1']['type']." <br>"; // this is a temporary test

    if ($_FILES['upLoad1']['error'] != 0) {
    $message1 = "Picture file 1 did not successfully upload" ;
    $message2 = "Error: ".$errors[$_FILES['upLoad1']['error']];
    require_once ("a_picts_fm.php");
    exit();
    } // endif

    if($_FILES['upLoad1']['tmp_name'] == "none") {
    $message1 = "Picture file 1 did not successfully upload" ;
    $message2 = "Check the file size. Must be less than 1MB";
    require_once ("a_picts_fm.php");
    exit();
    } // endif

    if(!ereg("image",$_FILES['upLoad1']['type'])) {
    $message1 = "The file you have selected for Picture 1 is not a recognised picture file.";
    $message2 = "Type = ".$_FILES['upLoad1']['type'];
    require_once ("a_picts_fm.php");
    exit();
    } // endif
    $pix1_y = "y";
    } // endif
    [/code]
    [/QUOTE]
    Well for a start all that could be replaced with:[code=php]if($N_pix1 != "")
    {
    echo "File type: ".$_FILES['upLoad1']['type']." <br>"; // this is a temporary test
    if ($_FILES['upLoad1']['error'] != 0)
    {
    $message1 = "Picture file 1 did not successfully upload" ;
    $message2 = "Error: ".$errors[$_FILES['upLoad1']['error']];
    require_once ("a_picts_fm.php");
    exit();
    }
    }[/code]
    And the function... no point with any of the transparency stuff because you are outputing as jpeg which doesn't support it anyway. That function could be reduced to:[code=php]function makeThumbnail($source, $t_ht,$N_pix_n)
    {
    if(!($o_im = @imageCreateFromString(@file_get_contents($source))))
    {
    return 'I could not open that image. (Corrupt or invalid type!)';
    }

    $t_wd = round($t_ht * ($o_wd = imagesx($o_im)) / ($o_ht = imagesy($o_im))) ;
    if(!($N_image = @imagecreatetruecolor($t_wd, $t_ht)))
    {
    return 'Problem with the image dimensions';
    }
    imagecopyresampled($N_image, $o_im, 0, 0, 0, 0, $t_wd, $t_ht, $o_wd, $o_ht);
    $destination = $_SERVER['DOCUMENT_ROOT']."/images/$N_pix_n";
    if(!(@imageJPEG($N_image,$destination,90)))
    {
    'I could not save '.$N_image.'. (Permission problem)!';
    }
    imageDestroy($o_im);
    imageDestroy($N_image);
    }[/code]
    Copy linkTweet thisAlerts:
    @DaveinLondonauthorNov 06.2006 — Are you sure ??

    I guess you are ?

    Please tell me - does the term "thumbnail" refer to something other than a

    resized (reduced in size) image ?

    If there is a technical differernce - what is this function doing -

    creating a thumbnail or resizing ?

    One other point -

    Initially you said that I should be using getImageSize($source)

    in order to check the file. You are not using it.

    Why ?

    (ps - its ok to change your mind ? I just want to learn the reason)

    Thank you for your input.

    I had seen that imageCreateFromString() function but was not sure how to use it. ?

    ALSO I wanted to be sure that if someone was using a gif or png or wbmp file, that I waould be able to use it and output a jpg

    Will this modified function that just uses imageCreateFromString() do that job ?

    Anyway,

    I am going to try it out and I'll let you know the results soon ?
    Copy linkTweet thisAlerts:
    @DaveinLondonauthorNov 06.2006 — OK - well I did the changes and ran the script.

    It appears to run ok but I get a broken image sign and when I checked then

    server images directory there was no jpg file created ?

    One question -

    In the function, if an error is returned eg:
    [code=php]return 'Problem with the image dimensions'; [/code]

    where will this error get sent ?

    I did not see any errors on the screen - but then I can not see where the script would print them. ?

    Here is the amended script:

    Look forward to your reply ?

    [code=php]<?php

    /*
    * THIS SCRIPT IS CALLED BY THE SUBMIT BUTTON ON THE FORM
    */


    // THIS FUNCTION IS CALLED IN THE PHP SCRIPT BELOW.


    function makeThumbnail($source, $t_ht,$N_pix_n)
    {
    if(!($o_im = @imageCreateFromString(@file_get_contents($source))))
    {
    return 'I could not open that image. (Corrupt or invalid type!)';
    }

    $t_wd = round($t_ht * ($o_wd = imagesx($o_im)) / ($o_ht = imagesy($o_im))) ;
    if(!($N_image = @imagecreatetruecolor($t_wd, $t_ht)))
    {
    return 'Problem with the image dimensions';
    }
    imagecopyresampled($N_image, $o_im, 0, 0, 0, 0, $t_wd, $t_ht, $o_wd, $o_ht);
    $destination = $_SERVER['DOCUMENT_ROOT']."/images/$N_pix_n";
    if(!(@imageJPEG($N_image,$destination,90)))
    {
    'I could not save '.$N_image.'. (Permission problem)!';
    }
    imageDestroy($o_im);
    imageDestroy($N_image);
    } // End of Function


    // ------------------------ NOW HERE IS THE MAIN SCRIPT ----------------

    require_once("my_functions.php"); // just contains the safe_sql()

    // SPECIFY THE HIEGHT OF THE THUMBNAIL (OR "RESIZED IMAGE") THAT I WANT TO CREATE
    $hgt = 120;

    // USED TO CREATE UNIQUE FILE NAME
    $today = date(U);

    // INITIATES VALUES
    $pix1_y = $pix2_y = $pix3_y = $pix4_y = $pix5_y = $pix6_y = "n";

    // Get the SIX file names from the form.

    $N_pix1 = safe_sql($_FILES['upLoad1']["name"]);
    $N_pix2 = safe_sql($_FILES['upLoad2']["name"]);
    $N_pix3 = safe_sql($_FILES['upLoad3']["name"]);
    $N_pix4 = safe_sql($_FILES['upLoad4']["name"]);
    $N_pix5 = safe_sql($_FILES['upLoad5']["name"]);
    $N_pix6 = safe_sql($_FILES['upLoad6']["name"]);

    // recommended checking.

    // possible PHP upload errors
    $errors = array(1 => 'php.ini max file size exceeded',
    2 => 'html form max file size exceeded',
    3 => 'file upload was only partial',
    4 => 'no file was attached');


    if($N_pix1 != "")
    {
    echo "File type: ".$_FILES['upLoad1']['type']." <br>"; // this is a temporary test
    if ($_FILES['upLoad1']['error'] != 0)
    {
    $message1 = "Picture file 1 did not successfully upload" ;
    $message2 = "Error: ".$errors[$_FILES['upLoad1']['error']];
    require_once ("a_picts_fm.php");
    exit();
    } // endif
    $pix1_y = "y";
    } // endif
    else{
    $N_pix1 = "none";
    } // end else


    //------------------------

    THIS IS THEN REPEATED ANOTHER FIVE TIMES
    SO THAT ALL SIX IMAGES ARE CHECKED.

    //------------------------

    /*
    * Everything seems ok - so we create the thumbnails from the temp_files.
    */

    if($pix1_y == "y"){ // ONLY IF THERE IS A FILE DO WE CALL THE FUNCTION
    $image = $_FILES['upLoad1']['tmp_name'];
    $N_pix1 = time()."-".$N_pix1; // CREATE A UNIQUE NAME
    makeThumbnail($image,$hgt,$N_pix1); // RUN THE FUNCTION ( SEE ABOVE )
    } // endif


    //------------------------

    THIS IS THEN REPEATED ANOTHER FIVE TIMES
    SO THAT ALL SIX IMAGES ARE CHECKED AND THE IMAGES ARE CREATED

    //------------------------


    /*
    * Update the ADVERT WITH THE IMAGE NAMES
    */

    // CONNECT AND UPDATE DB

    CONNECT

    $sql = "UPDATE $section SET
    image1 = '$N_pix1',
    image2 = '$N_pix2',
    image3 = '$N_pix3',
    image4 = '$N_pix4',
    image5 = '$N_pix5',
    image6 = '$N_pix6'

    WHERE ad_ref = '$ad_ref' ";

    mysql_query($sql)
    or die("could not execute $section UPDATE PICTURES query");


    // SO NOW ALL THE IMAGES ARE STORED
    // AND THE IMAGE FILES NAMES HAVE BEEN WRITTEN TO THE DB.
    // JOB DONE :)

    // RETURN TO MAIN SCRIPT

    require_once("MAIN-SCRIPT");
    Exit();
    ?> [/code]
    Copy linkTweet thisAlerts:
    @bokehNov 06.2006 — Well in your function you had this:[code=php]return (isset($ermsg)?$ermsg:NULL); [/code]That is the return value. It gets returned here:[code=php]if($pix1_y == "y"){ // ONLY IF THERE IS A FILE DO WE CALL THE FUNCTION
    $image = $_FILES['upLoad1']['tmp_name'];
    $N_pix1 = time()."-".$N_pix1; // CREATE A UNIQUE NAME
    makeThumbnail($image,$hgt,$N_pix1); // RUN THE FUNCTION ( SEE ABOVE )
    } // endif [/code]
    This piece of code though ignores the return value from either function. As a temporary measure change: [code=php]makeThumbnail($image,$hgt,$N_pix1);[/code] to: [code=php]echo makeThumbnail($image,$hgt,$N_pix1);[/code]But really you should have a conditional statement here to handle this. Also I would prefer to see you using booleans instead of strings in the following context: [code=php]$pix1_y = "y";[/code]
    Copy linkTweet thisAlerts:
    @DaveinLondonauthorNov 06.2006 — Thanks.

    Changed and ran the script.

    I get "I could not open that image. (Corrupt or invalid type!)"

    This corresponds to a failure at:

    if(!($o_im = @imageCreateFromString(@file_get_contents($source))))

    Now as I said in my first post, this image ( actually I tried several images) is from my new digital camera.

    The images display fine on my computer.

    Is there a way to check my image before sending it ?

    Thousands of people will have bought the same camaera so I would like to get to the bottom of this problem !

    Thanks.
    Copy linkTweet thisAlerts:
    @bokehNov 06.2006 — Have you got an image I can test?
    Copy linkTweet thisAlerts:
    @DaveinLondonauthorNov 07.2006 — OK uploading one of them. ?
    Copy linkTweet thisAlerts:
    @DaveinLondonauthorNov 07.2006 — OK

    One of the images that I have been trying to upload is

    called IMAG0005.JPG

    I have ftp'ed this to my server and done a script to display it.

    You can see it at :

    http://www.yodbod.com/image.php

    You can also try the image upload script on the website as I am working on the live site ?

    http://www.yodbod.com


    Just click on "Place an advert" after entering some stuff and submitting it,

    the picture upload script runs.

    Thanks
    Copy linkTweet thisAlerts:
    @DaveinLondonauthorNov 07.2006 — I just checked "the manual" and saw that

    imageCreateFromString() should deal with the images that I want.

    So the answer to my question:

    ALSO I wanted to be sure that if someone was using a gif or png or wbmp file, that I would be able to use it and output a jpg

    Will this modified function that just uses imageCreateFromString() do that job ?[/QUOTE]


    is - yes ( I think :o )

    From Manual imagecreatefromstring() returns an image identifier representing the image obtained from the given string. These types will be automatically detected if your build of PHP supports them: JPEG, PNG, GIF, WBMP, and GD2. [/QUOTE]

    ( hope that helps someone else )
    Copy linkTweet thisAlerts:
    @bokehNov 07.2006 — It just looks like that file is incompatible with GD. [I]getimagesize()[/I] doesn't have any trouble with it but [I]imagecreatefromstring()[/I] and [I]imagecreatefromjpeg()[/I] raise the following error messages:[CODE][B]Warning:[/B] imagecreatefromstring() Passed data is not in 'JPEG' format
    [B]Warning:[/B] imagecreatefromstring() Couldn't create GD Image Stream out of Data
    [B]Warning:[/B] imagecreatefromjpeg() 'test-daveinlondon.jpg' is not a valid JPEG file[/CODE]
    Copy linkTweet thisAlerts:
    @DaveinLondonauthorNov 07.2006 — There was a little application called jhead that I used to clean the extra header info from jpg file.

    Could it be that some extra header info is causing a problem ?

    I used to have this in the script but maybe the path wasn't enough to make it work ?

    exec("jhead -purejpg ".$source); // cleans up jpg headers

    Have you used jhead.exe ?

    available from :

    http://www.sentex.net/~mwandel/jhead/

    If you parse the file with this maybe it will work ?
    Copy linkTweet thisAlerts:
    @bokehNov 07.2006 — If you parse the file with this maybe it will work ?[/QUOTE]No it doesn't. Also I tried the file in a couple of other programs and that file raises a warning in them too.

    [B]Corrupt JPEG data:[/B] 6 extraneous bytes before marker 0xd9
    Copy linkTweet thisAlerts:
    @DaveinLondonauthorNov 07.2006 — Well, what I'll do is take some more pictures at different resolutions and try them.

    The camera is a Vivitar ViviCam 3105s

    Thanks

    PS - is the jhead.exe a usefull app ?

    Do you think that I should put it in my script to "clean up" jpg files ?
    Copy linkTweet thisAlerts:
    @bokehNov 07.2006 — The camera is a Vivitar ViviCam 3105s[/QUOTE]What made you buy a Vivitar?PS - is the jhead.exe a usefull app ?[/QUOTE]I don't see any benefit in this context. The source files are being deleted, only GD's creations remain.
    Copy linkTweet thisAlerts:
    @DaveinLondonauthorNov 09.2006 — What made you buy a Vivitar?[/QUOTE]

    I dont know much about digital cameras.

    Is Vivitar rubbish ?

    Pictures look fine on pc.

    Is the Vivitar creating strange jpg files ?

    What is the problem - why can these jpg files not be used by:

    imageCreateFromString() function ?

    Actually is it the

    imageCreateFromString() function ?

    or the

    @file_get_contents() function ?

    Anyway some seems to be wrong with th jpg files and I thought that some kind of parser might help -- no ???
    Copy linkTweet thisAlerts:
    @so_is_thisNov 10.2006 — One meg is 1048576 bytes. ?[/QUOTE]
    Not if you follow ISO standards.[/QUOTE]

    I know, not your fault -- but that is so ridiculously stupid it is not even funny. ISO cannot hope to dictate how a computer counts. If you want to say, "a million bytes" then that would be an accurate statement. But to say, "a megabyte is a million bytes" is taking the term out of the context of its definition.

    Divisions of groups of numbers are predicated on when a particular number base reaches a point where the number starts with 1 and ends with all zeroes. Thus, the decimal system has these groups and counts in units of whatever you choose:

    10^0 = 1 = one unit

    10^3 = 1000 = thousands

    10^6 = 1000000 = millions

    10^9 = 1000000000 = billions

    ...etc...

    The computer, on the other hand, does not count in decimal. As you know, it counts in binary. Thus, the computer's binary system has these groups and only counts its storage (memory, disk, etc.) in units of bytes:

    2^0 = 1 = one byte

    2^10 = 10000000000 = kilobytes (decimal 1,024)

    2^20 = 100000000000000000000 = megabytes (decimal 1,048,576)

    2^30 = 1000000000000000000000000000000 = gigabytes (decimal 1,073,741,824)

    ...etc...

    I know I'm not telling you anything you don't already know. Therefore, you also know that my statement was accurate to begin with and you also know that it was just being argumentative, on your part, to throw in a standard which was written for convenience and was not written for accuracy.
    Copy linkTweet thisAlerts:
    @bokehNov 10.2006 — I know, not your fault [...] and you also know that it was just being argumentative, on your part, to throw in a standard which was written for convenience and was not written for accuracy.[/QUOTE]Which side of the pond are you on??? According to the Oxford English Dictionary kilo (from the Greek) which had already been in common use for quite some time was officially adopted into the English in 1795 (19 years after the declaration of independence of the United States of America). It was officially accepted as an SI unit in 1960 and has always signified one thousand. Later in a moment of boredom US Congress decided that the Kilobyte (note the capital K) would be the accepted unit of data storage. It has never though been accepted as an international standard and is different from the kilobyte and kilobit (note the lower case k signifying 1000) which are used in data transfer specifications, probably to make people believe they are getting more bang for their buck when in fact they are not.
    Copy linkTweet thisAlerts:
    @so_is_thisNov 10.2006 — What I'm talking about has nothing to do with US vs. UK nor the US Congress. I'm also quite aware of the Greek definitions -- but, again, that is neither here nor there. When you buy a Gigabte of memory -- even in Europe -- how many bytes of memory do you get? The ISO standard of 1 billion? No. You get 1,073,741,824 bytes of memory. So, don't tell me that a megabyte is a million bytes. :b
    Copy linkTweet thisAlerts:
    @bokehNov 10.2006 — don't tell me that a megabyte is a million bytes.[/QUOTE][URL=http://en.wikipedia.org/wiki/Mega][B]Computing:[/B]

    In computing, mega- can sometimes denote 1,048,576 (220) of information units (example: a megabyte, a megaword), but can denote 1,000,000 (106) of other quantities, for example, transfer rates: 1 megabit/s = 1,000,000 bit/s.

    The prefix mebi- has been suggested as an alternative for 220 to avoid ambiguity[/URL]
    Copy linkTweet thisAlerts:
    @so_is_thisNov 10.2006 — Like I said ... don't tell me. Tell those that design computer hardware.

    Only when they change will the definitions change.
    Copy linkTweet thisAlerts:
    @bokehNov 10.2006 — you also know that it was just being argumentative, on your part[/QUOTE]Who me??? Argumentative??? I don't think so!!!
    Copy linkTweet thisAlerts:
    @DaveinLondonauthorNov 10.2006 — Thanks guys for that lively debate ?

    Would appreciate your thoughts on the question I raised ?


    --------------------------------------------------
    What made you buy a Vivitar? [/QUOTE]

    I dont know much about digital cameras.

    Is Vivitar rubbish ?

    Pictures look fine on pc.

    Is the Vivitar creating strange jpg files ?

    What is the problem - why can these jpg files not be used by:

    imageCreateFromString() function ?

    Actually is it the

    imageCreateFromString() function ?

    or the

    @file_get_contents() function ?

    Anyway something seems to be wrong with th jpg files and I thought that some kind of parser might help -- no ???


    ----------------------------------------------------------------------

    thanks ?
    Copy linkTweet thisAlerts:
    @jeddikNov 11.2006 — Well Bokeh wrote:

    Corrupt JPEG data: 6 extraneous bytes before marker 0xd9[/QUOTE]

    That looks like extra data that could be stripped out.

    Maybe Bokeh can say what utility he used to test the image with

    and if he knows any way to clean up the file...

    I think that would help you a bit. ?

    PS try searching Google for Vivitar ??

    You may find some help.
    Copy linkTweet thisAlerts:
    @bokehNov 11.2006 — Maybe Bokeh can say what utility he used to test the image[/QUOTE]This error presents itself in more than one program. Since the GIMP is accepted as de facto I tried it in that and sure enough that program also states this error. My advice would be return the camera and buy one that doesn't produce files that raise warnings in multiple applications.
    Copy linkTweet thisAlerts:
    @jeddikNov 12.2006 — Thanks - I will download and use GIMP.

    I don't need to buy a new camera, I have opened the files in Serif PhotoPlus and then re-exported the image as a .jpg

    These new files upload on my free advertisment site

    the website without any problem.

    If you want to test it out please do so at:

    http://www.yodbod.com

    This has worked fine for me but it is not really the solution.

    I wanted a server side solution that will clean up a corrupted .jpg file.

    After all there are going to be thousands of people who buy this camera or

    other cameras that also output variations of .jpg that php has difficulty using.

    Any final suggestions for this ??
    Copy linkTweet thisAlerts:
    @bokehNov 12.2006 — I don't need to buy a new camera, I have opened the files in Serif PhotoPlus and then re-exported the image as a .jpg[/QUOTE]I don't know where you come from and what the rules are in your country but if I bought a camera that produced output that multiple software applications were to report as "errornous" I'd be expecting a refund without any question.
    ×

    Success!

    Help @DaveinLondon spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.18,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...