Potrzebuje pomocy w stworzeniu zapytania do bazy, poniżej kod. Obecnie kod dodaje do bazy kolejne zdjęcie, macie pomysł jak zmodyfikować zapytanie tak aby skrypt aktualizował rekord o konkretnym id.
<form method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" enctype="multipart/form-data"> Select Image File: <input type="file" name="userfile" size="40"> <input type="hidden" name="MAX_FILE_SIZE" value="10000000"> <select name="image_ctgy"> </select> <br /> <input type="submit" value="submit"> </form>
<?php /*** check if a file was submitted ***/ { } else { try { upload(); /*** give praise and thanks to the php gods ***/ } catch(PDOException $e) { } catch(Exception $e) { } } /** * * the upload function * * @access public * * @return void * */ function upload(){ /*** check if a file was uploaded ***/ if(is_uploaded_file($_FILES['userfile']['tmp_name']) && getimagesize($_FILES['userfile']['tmp_name']) != false) { /*** an array of allowed categories ***/ if(filter_has_var(INPUT_POST, "notset") !== false || in_array($_POST['image_ctgy'], $cat_array) !== false) { $image_ctgy = filter_input(INPUT_POST, "image_ctgy", FILTER_SANITIZE_STRING); } else { throw new Exception("Invalid Category"); } /*** get the image info. ***/ /*** assign our variables ***/ $image_type = $size['mime']; $image_width = $size[0]; $image_height = $size[1]; $image_size = $size[3]; $image_name = $_FILES['userfile']['name']; $maxsize = 99999999; /*** check the file is less than the maximum file size ***/ if($_FILES['userfile']['size'] < $maxsize ) { /*** create a second variable for the thumbnail ***/ $thumb_data = $_FILES['userfile']['tmp_name']; /*** get the aspect ratio (height / width) ***/ $aspectRatio=(float)($size[0] / $size[1]); /*** the height of the thumbnail ***/ $thumb_height = 100; /*** the thumb width is the thumb height/aspectratio ***/ $thumb_width = $thumb_height * $aspectRatio; /*** get the image source ***/ $src = ImageCreateFromjpeg($thumb_data); /*** create the destination image ***/ $destImage = ImageCreateTrueColor($thumb_width, $thumb_height); /*** copy and resize the src image to the dest image ***/ ImageCopyResampled($destImage, $src, 0,0,0,0, $thumb_width, $thumb_height, $size[0], $size[1]); /*** start output buffering ***/ /*** export the image ***/ imageJPEG($destImage); /*** stick the image content in a variable ***/ /*** clean up a little ***/ /*** connect to db ***/ $dbh = new PDO("mysql:host=localhost;dbname=db", 'user', 'pass'); /*** set the error mode ***/ $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); /*** prepare the sql ***/ $stmt = $dbh->prepare("INSERT INTO tblob (image_type ,image, image_height, image_width, image_thumb, thumb_height, thumb_width, image_ctgy, image_name) VALUES (? ,?, ?, ?, ?, ?, ?, ?, ?)"); $stmt->bindParam(1, $image_type); $stmt->bindParam(2, $imgfp, PDO::PARAM_LOB); $stmt->bindParam(3, $image_height, PDO::PARAM_INT); $stmt->bindParam(4, $image_width, PDO::PARAM_INT); $stmt->bindParam(5, $image_thumb, PDO::PARAM_LOB); $stmt->bindParam(6, $thumb_height, PDO::PARAM_INT); $stmt->bindParam(7, $thumb_width, PDO::PARAM_INT); $stmt->bindParam(8, $image_ctgy); $stmt->bindParam(9, $image_name); /*** execute the query ***/ $stmt->execute(); } else { /*** throw an exception is image is not of type ***/ throw new Exception("File Size Error"); } } else { // if the file is not less than the maximum allowed, print an error throw new Exception("Unsupported Image Format!"); } } ?>
Z góry dzięki za pomoc.