Napisano: 07 Jun 2011 23:14
Pozdrav,
Interesuje me kako mogu da insertujem nazive slika u mysql. Želim svako ime slike da ubacim u novi red (autoincrement)
kako treba da mi izgleda query?
običan query bi izgledao ovako
INSERT INTO images (id, name, ordering, ruta, id_proizvoda) VALUES (%s, %s, %s, %s, %s)"
ali je problem sto ja imam vise slika
Našao sam ovako nešto na kon googlanja ali mi nije baš jasan ovaj red pa ako može neko da mi ga objasni
insert into images (image) values (null);
update images set image=concat(last_insert_id(), '.jpg') where id=last_insert_id();
druga stvar koja me interesuje je kako mogu proveritit da li je slika (jpg ili gif)
Evo koda sa kojim uploadujem slike
$i = '0';
$malaslika = 'resized';
$id = $row_Recordset1['id'];
function imgReisize($uploadedfile, $Destination, $Thumb){
//this is the function that will resize and copy our images
// Create an Image from it so we can do the resize
$src = imagecreatefromjpeg($uploadedfile);
// Capture the original size of the uploaded image
list($width,$height)=getimagesize($uploadedfile);
// resize slika
$newwidth=480;
$newheight=($height/$width)*480;
$tmp=imagecreatetruecolor($newwidth,$newheight);
// this line actually does the image resizing, copying from the original
// image into the $tmp image
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
// now write the resized image to disk. I have assumed that you want the
$filename = $Destination;
imagejpeg($tmp,$filename,100);
// resize malih slika
$newwidth=100;
$newheight=($height/$width)*100;
$tmp=imagecreatetruecolor($newwidth,$newheight);
//resizujem slike
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
// upload slika
$filename = $Thumb;
imagejpeg($tmp,$filename,100);
imagedestroy($src);
imagedestroy($tmp);
echo '
<div style="float:left; width:100px;margin:10px;padding:2px;border:1px solid#ccc;"><img src="'.$filename.'"></div>';
}
echo '<br /><br /> <a href="index.php">go back</a><br />';
if(isset($_POST['submit'])){
$imgNumb='1'; //ime slike 1
if (!preg_match("/\.(gif|jpg)$/i", $_FILES['img1']['name'] ) ) {
echo "<br /><br />Slika moze biti samo u .gif ili .jpg formatu<br />
<a href=\"index.php\">pokusaj ponovo</a>";
unlink($_FILES['img1']['tmp_name']);
exit();
}
if (!is_dir("../../slike/$id"))
mkdir("../../slike/$id", 0777);
$DestinationDir="../../slike/$id/"; //Place the destination dir here
$ThumbDir="../../slike/$id/"; //Place the thumb dir here
while($_FILES["img".$imgNumb]['tmp_name']){
$Unique=$i++; // ime ostalih slika
$destination=$DestinationDir.($i).".jpg";
$thumb=$DestinationDir.($i).'_resize'.".jpg";
imgReisize($_FILES['img'.$imgNumb]['tmp_name'], $destination, $thumb);
$imgNumb++;
}
}
;
mogu da proverim format slike (img1) sa ovim redom
if (!preg_match("/\.(gif|jpg)$/i", $_FILES['img1']['name'] ) ) {
echo "<br /><br />Slika moze biti samo u .gif ili .jpg formatu<br />
<a href=\"index.php\">pokusaj ponovo</a>";
unlink($_FILES['img1']['tmp_name']);
exit();
kako mogu da proverim istale slike (img2, img3 itd)
forma mi izgleda ovako
<form action="" method="post" enctype="multipart/form-data" name="form" id="form" onsubmit="return validate_form ( );" >
<input type="file" name="img1"/><br />
<input type="file" name="img2"/><br />
<input type="file" name="img3"/><br />
<input type="file" name="img4"/><br />
<input type="file" name="img5"/><br />
<input type="file" name="img6"/><br />
<input type="submit" name="submit" value="Submit"/>
|