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:
"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 this bit of code:
PHP Code:
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
I have two questions:
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:
PHP Code:
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
where in my script does it specify a 500k limit ?
Why should a tmp_name = none mean that the file was over 500K ?
The whole upload script is here:
PLEASE let me know where you think I may have made mistakes
PHP Code:
<?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 = 'D\web\images'."\\".$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");
THE REST IS NOT IMPORTANT
?>