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
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
?>