I can't be far wrong...
Posted: Wed Nov 18, 2009 3:03 pm
Hi all,
trying to finish my upload images script and it all works fine except for one annoying
glitch. Users are asked to choose an image then choose a gallery to post it to from a
drop down menu. I have error checking for filetype, filesize, whether they have actually chosen
an image but I can't get the syntax right for checking if they have chosen a gallery from the
drop down. The default setting for the menu is "Which Gallery?" and at present the code will
allow me to upload an image whcih is then inserted into the db as belonging to the gallery "Which Gallery?"
instead of portraits / landscapes etc.,
Can anyone help ?
Best wishes
Monty
Drop down in html:
<select name="gowhere" id="gowhere">
The relevant part of the upload script: should be round about line 18
trying to finish my upload images script and it all works fine except for one annoying
glitch. Users are asked to choose an image then choose a gallery to post it to from a
drop down menu. I have error checking for filetype, filesize, whether they have actually chosen
an image but I can't get the syntax right for checking if they have chosen a gallery from the
drop down. The default setting for the menu is "Which Gallery?" and at present the code will
allow me to upload an image whcih is then inserted into the db as belonging to the gallery "Which Gallery?"
instead of portraits / landscapes etc.,
Can anyone help ?
Best wishes
Monty
Drop down in html:
<select name="gowhere" id="gowhere">
The relevant part of the upload script: should be round about line 18
Code: Select all
if ((!empty($_FILES['fileField'])) && ($_FILES['fileField']['error'] == 0)){
$image = $_FILES['fileField']['name'];
$filename = stripslashes($_FILES['fileField']['name']);
$extension = getExtension($filename);
$extension = strtolower($extension);
//Filetype check
if (!in_array($extension,$acceptableextensions)){
exit("Upload failed.<BR>Unacceptable file type.<br. Use only jpg, jpeg, png or fig formats");
echo '<h1>Only try to upload .jpg, .jpeg, .png and .gif files!</h1>';
$errors=1;
//Filesize check
} else if ($_FILES['fileField']['size'] > $maxfilesize ) {
$error_msg = 'Ooops - your image was too large,<br> 250kb Maximum. Please try again.';
unlink($_FILES['fileField']['tmp_name']);
// Chose a Gallery from the drop down menu check
if (isset ($_FILES['gowhere']) && ($_FILES['gowhere'] != 'Which Gallery?')) {
$gowhere = mysql_real_escape_string ($_FILES['gowhere']);
} else {
$gowhere = FALSE;
$error_msg = "<p>Please select a Gallery to post your image to.</p>";
}
} else {
// rename the picture incrementally
$extension = getExtension($filename);
$extension = strtolower($extension);
$groovy = sizeof(glob("members/$id/images/*"));
$groovy = ++$groovy;
$image_name=$groovy.'.'.$extension;
$newname="".$image_name;
$gowhere = mysql_real_escape_string($_POST['gowhere']);
// NOW make the resize call !
//img_resize ($_FILES ['fileField'] [ 'name'], $_FILES [ 'fileField'] [ 'tmp_name'], 25, $newname);
// INSERT image into the DB
$sql = mysql_query("INSERT INTO pictures
(UID,filename,dirpath,gallery,dtadded)
VALUES ('$id','$newname','/members/$id/images/$newname','$gowhere',now())")
or die (mysql_error());
$place_file = move_uploaded_file( $_FILES['fileField']['tmp_name'], "members/$id/images/".$newname);
chmod ("members/$id/images/$newname", 0666);