Thanks for all the help,
I am almost there…
I tried your proposals but I can not get it to work. Somehow I’m overseeing something but after a while it all looks the same.
I open the page with:
http://192.168.2.3/catalogus/admin/img/submit.php?id=21 As you can see there is an “id” .
When I use this “id” hard coded the update query works.
As far I can see, after submitting the form the images will be uploaded and the query executed. After this the URL changes into :
http://192.168.2.3/catalogus/admin/img/submit.php?upload_message=Afbeelding%20ge-upload&upload_message_type=success&show_image=ben440.jpg
This part gives me the :-
[php] // GET ID FROM URL
$id=$_GET[‘id’] ;
// insert image name
//Doesnot work | mysql_query(“UPDATE Prod SET image = '”.$_FILES[“image_upload_box”][“name”]."’ WHERE id = ‘$id’ ");
mysql_query("UPDATE Prod SET image = ‘image_upload_box’ WHERE id = ‘21’ "); [/php]
What do I wrong?
The total code so far…
[php]<?php ini_set("memory_limit", "200000000"); // for large images so that we do not get "Allowed memory exhausted"?>
<?php // Connect DBase
include ("../../inc/connect_Shop.inc.php");
?>
<?php
// upload the file
if ((isset($_POST["submitted_form"])) && ($_POST["submitted_form"] == "image_upload_form")) {
// file needs to be jpg,gif,bmp,x-png and 4 MB max
if (($_FILES["image_upload_box"]["type"] == "image/jpeg" || $_FILES["image_upload_box"]["type"] == "image/pjpeg" || $_FILES["image_upload_box"]["type"] == "image/gif" || $_FILES["image_upload_box"]["type"] == "image/x-png") && ($_FILES["image_upload_box"]["size"] < 4000000))
{
// soorten afbeeldingen
// if uploaded image was JPG/JPEG
if($_FILES["image_upload_box"]["type"] == "image/jpeg" || $_FILES["image_upload_box"]["type"] == "image/pjpeg"){
$image_source = imagecreatefromjpeg($_FILES["image_upload_box"]["tmp_name"]);
}
// if uploaded image was GIF
if($_FILES["image_upload_box"]["type"] == "image/gif"){
$image_source = imagecreatefromgif($_FILES["image_upload_box"]["tmp_name"]);
}
// BMP doesn't seem to be supported so remove it form above image type test (reject bmps)
// if uploaded image was BMP
if($_FILES["image_upload_box"]["type"] == "image/bmp"){
$image_source = imagecreatefromwbmp($_FILES["image_upload_box"]["tmp_name"]);
}
// if uploaded image was PNG
if($_FILES["image_upload_box"]["type"] == "image/x-png"){
$image_source = imagecreatefrompng($_FILES["image_upload_box"]["tmp_name"]);
}
// Afbeelding upload 3 verschillende dir's
//standaard
$remote_file = "../../images/".$_FILES["image_upload_box"]["name"];
imagejpeg($image_source,$remote_file,100);
chmod($remote_file,0644);
//klein
$remote_file_kl = "../../images_kl/".$_FILES["image_upload_box"]["name"];
imagejpeg($image_source,$remote_file_kl,100);
chmod($remote_file_kl,0644);
//Thumb
$remote_file_tmb = "../../images_tmb/".$_FILES["image_upload_box"]["name"];
imagejpeg($image_source,$remote_file_tmb,100);
chmod($remote_file_tmb,0644);
// get width and height of original image
list($image_width, $image_height) = getimagesize($remote_file);
if($image_width>$img_width || $image_height >$img_height){
$proportions = $image_width/$image_height;
if($image_width>$image_height){
$new_width = 800;
$new_height = round(800/$proportions);
$new_width_kl = 160;
$new_height_kl = round(160/$proportions);
$new_width_tmb = 100;
$new_height_tmb = round(100/$proportions);
}
else{
$new_height = 800;
$new_width = round(800*$proportions);
$new_height_kl = 160;
$new_width_kl = round(160*$proportions);
$new_height_tmb = 100;
$new_width_tmb = round(100*$proportions);
}
$image_source = imagecreatefromjpeg($remote_file);
$new_image = imagecreatetruecolor($new_width , $new_height);
imagecopyresampled($new_image, $image_source, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);
imagejpeg($new_image,$remote_file,100);
$new_image_kl = imagecreatetruecolor($new_width_kl , $new_height_kl);
imagecopyresampled($new_image_kl, $image_source, 0, 0, 0, 0, $new_width_kl, $new_height_kl, $image_width, $image_height);
imagejpeg($new_image_kl,$remote_file_kl,100);
$new_image_tmb = imagecreatetruecolor($new_width_tmb , $new_height_tmb);
imagecopyresampled($new_image_tmb, $image_source, 0, 0, 0, 0, $new_width_tmb, $new_height_tmb, $image_width, $image_height);
imagejpeg($new_image_tmb,$remote_file_tmb,100);
// GET ID FROM URL
$id=$_GET['id'] ;
// insert image name
//Doesnot work | mysql_query("UPDATE Prod SET image = '".$_FILES["image_upload_box"]["name"]."' WHERE id = '$id' ");
mysql_query("UPDATE Prod SET image = 'image_upload_box' WHERE id = '21' ");
imagedestroy($new_image);
imagedestroy($new_image_kl);
imagedestroy($new_image_tmb);
}
imagedestroy($image_source);
header("Location: submit.php?upload_message=Afbeelding ge-upload&upload_message_type=success&show_image=".$_FILES["image_upload_box"]["name"]);
exit;
}
else{
header("Location: submit.php?upload_message=Bestand moet een jpg, gif or png zijn en kleiner dan4MB &upload_message_type=error");
exit;
}
}
?>
Afbeeldingen uploaden
<!--
body,td,th {
font-family: Arial, Helvetica, sans-serif;
color: #333333;
font-size: 12px;
}
.upload_message_success {
padding:4px;
background-color:#009900;
border:1px solid #006600;
color:#FFFFFF;
margin-top:10px;
margin-bottom:10px;
}
.upload_message_error {
padding:4px;
background-color:#CE0000;
border:1px solid #990000;
color:#FFFFFF;
margin-top:10px;
margin-bottom:10px;
}
–>
Afbeelding uploaden
<?php if(isset($_REQUEST['upload_message'])){?>
<div class="upload_message_<?php echo $_REQUEST['upload_message_type'];?>">
<?php echo htmlentities($_REQUEST['upload_message']);?>
</div>
<?php }?>
|
Afbeelding, soorten jpg, gif, png:
uploaden kan even duren !
<label>De 3 afbeeldingen hebben Max. maten: <br>800x800pc<br>160x160pc<br>100x100pc<br> </label>
</TR></TD><TR><TD ALIGN=LEFT>
<p style="padding:5px; border:1px solid #EBEBEB; background-color:#FAFAFA;">
<strong>Notes:</strong><br />
Als de afbeedling ge-upload is dan zal deze hieronder getoond worden. Afmeting max 160x160pc.
</tr></td><tr><td align=middle>
<?php if(isset($_REQUEST['show_image']) and $_REQUEST['show_image']!=''){
?>
<?php } ?>
[/php]
Best regard,
Rob
|