ragrim Posted September 14, 2010 Share Posted September 14, 2010 Hi, Ive built a website with an image gallery and when i uploaded it to a webhost i discovered they dont have PDO enabled, so ive tried to change my script to work without PDO but ive had no luck, i was hoping someone could look at my script (which i found on the net) and help me to remove the GDO part from it if its possible. Ive work around it not using PDO but this is the only script i can find to upload thumbnails. any help would be muchly appreciated. <?php if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $category = $_POST['category']; $username = $_POST['username']; $description = $_POST['description']; $date = date("Y-m-d"); $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); $content = addslashes($content); fclose($fp); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } /*** get the image info. ***/ $size = getimagesize($_FILES['userfile']['tmp_name']); /*** assign our variables ***/ $image_type = $size['mime']; $imgfp = fopen($_FILES['userfile']['tmp_name'], 'rb'); $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 = 200; /*** 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 ***/ ob_start(); /*** export the image ***/ imageJPEG($destImage); /*** stick the image content in a variable ***/ $image_thumb = ob_get_contents(); /*** clean up a little ***/ ob_end_clean(); /*** 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 upload (type, content, thumbnail, image_name, description, uploaddate, size, category) VALUES (? ,?, ?, ?, '$description', NOW(), '$filesize', '$category')"); $stmt->bindParam(1, $image_type); $stmt->bindParam(2, $imgfp, PDO::PARAM_LOB); $stmt->bindParam(3, $image_thumb, PDO::PARAM_LOB); $stmt->bindParam(4, $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!"); } header( 'Location: admin.php?location=upload.php' ) ; ?> Quote Link to comment https://forums.phpfreaks.com/topic/213432-need-to-help-to-modify-this-script/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.