Forum Moderators: coopster
I am still struggling with this CMS..but getting there :) anyway.. the CMS needs to have an admin section for inserting new records. This needs to include upto 6 images which i will be storing in the DB as path names using unique IDs.
My problem is..
P.S picture 1 needs to be thumbnailed aswell.
All must have restricted size and be jpgs.
Is it better to insert 1 at a time? if so how?
Is it better to insert all 6 via 6 browse fields in the form? if so will this potentially burn temp memory set at 8mb?
to be honest i am little lost to the best solution so any help here would be great..
TIA
my table will have 6 fields, picture1, picture2, picture3 etc.
each one is populated with a unique ID for the image. example; uploads/029329743.jpg
I dont need to thumbnail these now as i can do that on the fly. But i would like help creating a while loop (i think) to insert each image name into the DB and upload each file to uploads/
Also this needs to be flexible just incase they dont add all the images, and possibly increase it from 6 at a later date..
Also how easy would it be to change an image after uploading and remove the old one at the same time?
Thanks
if ($_FILES['userfile']['name'][$q] == "") continue;
$num = $num + 1;
$sql = "SELECT pic_id FROM pics ORDER BY pic_id DESC LIMIT 1";
$result = mysql_query($sql);
big thanks for any help here its driving me mad
$uploaddir = 'uploads/';
$tot = count($userfile);
$num = 0;
for($q=0;$q<$tot;$q++){
print "".$tot."<br />";
$picture[$q] = $_FILES['userfile']['tmp_name'][$q];
print "".$picture[$q]."<br />";
$picture[$q] = "".uniqid(I).".jpg";
print "".$picture[$q]."<br />";
You must be uploading multiple files at the same time, therefore the
[$q] index. The if statement is checking to see whether or not the original name of the file on the client machine was blank for that particular file on your form. If it is blank, skip over it as the user didn't browse their pc to pick up a file for that particular input field on the form.
$conn = db_connect();
// image uploader
$uploaddir = 'uploads/';
$tot = count($userfile);
$num = 0;
for($q=0;$q<$tot;$q++){
$picture[$q] = $_FILES['userfile']['tmp_name'][$q];
print "".$picture[$q]."<br />";
if ($_FILES['userfile']['name'][$q] == "") continue;
$num = $num + 1;
$picturename[$q] = "".uniqid(I).".jpg";
print "\$picturename = ".$picturename[$q]."<br />";
move_uploaded_file($_FILES['userfile']['tmp_name'][$q], $uploaddir . $picturename[$q]);
$filepath = 'uploads/' .$picturename[$q];
print $filepath;
$sql = "update brokerage
set 'picture[$q]' = '$filepath'
where id = 11";
$result = mysql_query($sql, $conn);
if (!$result) {
print "There was a database error when executing <pre>$sql</pre>";
print mysql_error();
exit;
}
}
@header('Location: '.$HTTP_POST_VARS['destination']);
results are as follows but i see now error :(
/tmp/php4PzRA9
$picturename = I4006a48a5b036.jpg
uploads/I4006a48a5b036.jpgThere was a database error when executing
update brokerage
set 'picture[0]' = 'uploads/I4006a48a5b036.jpg'
where id = 11
You have an error in your SQL syntax near ''picture[0]' = 'uploads/I4006a48a5b036.jpg' where id = 11' at line 2
the if statement checks to see if its and update if not then this parts process... apart from the file uploader :/
else { // It's a new boat
$sql = "insert into brokerage
(type,price,make,model,year,engine_type,engine_hrs,fuel,LOA,beam,accommodation,brief,description,finance,warranty,date,maxspeed,lying)
values
('$type','$price','$make','$model','$year','$engine_type','$engine_hrs','$fuel','$LOA','$beam','$accommodation','$brief','$description','$finance','$warranty','$date','$maxspeed','$lying')";
$result = mysql_query($sql, $conn);
$boatID = mysql_insert_id();
$uploaddir = 'uploads/'; // image uploader
$tot = count($userfile);
$num = 0;
for($q=0;$q<$tot;$q++){
$picture[$q] = $_FILES['userfile']['tmp_name'][$q];
if ($_FILES['userfile']['name'][$q] == "") continue;
$picturename[$q] = "".uniqid(I).".jpg";
move_uploaded_file($_FILES['userfile']['tmp_name'][$q], $uploaddir . $picturename[$q]);
$filepath = 'uploads/' .$picturename[$q];
$imagesql = "update brokerage
set picture".$num." = '$filepath'
where id = $boatID";
$imageresult = mysql_query($imagesql, $conn);
$num = $num + 1;
}
}