wpisolutions Posted September 24, 2011 Share Posted September 24, 2011 i need to upload files to a different folder dependint on option in form, make thumbnails, and store title and src for image and thumb in database table dependant on category. i think i'm pretty close, but there's still something wrong. Here is my upload form : <form enctype="multipart/form-data" action="upload.php" method="POST"> Photo: <input type="file" name="photo"><br> Category: <select name="cat"> <option value="weddings">Weddings</option> <option value="music">Music</option> <option value="portraits">Portraits</option></select> Title: <input type="text" name="title"><br> <input type="submit" value="Upload photo"> </form> form processed by upload.php : <?php require "db.php"; //Get form info $name=$_POST['name']; $title=$_POST['title']; $category=$_POST['cat']; $pic=($_FILES['photo']['name']); //set target dir source file width height $target = $cat."/"; $src = $target . basename( $_FILES['photo']['name']); $destination = $cat."/thumbs"; $thumbsrc = $destination . basename( $_FILES['photo']['name']); $width = 200; $height = 200; header("content-type: image/jpeg"); $src_img = imagecreatefromjpeg("$src"); $srcsize = getimagesize("$dest"); $dst_img = imagecreatetruecolor($width, $height); imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $width, $height, $srcsize[0], $srcsize[1]); imagejpeg($dst_img); //Unstert into db mysql_query("INSERT INTO `$category` VALUES ('$name', 'Stitle', '$src, $thumbsrc')") ; //move photo if(move_uploaded_file($_FILES['photo']['tmp_name'], $fulltarget)) { //Ok echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; } else { //not ok echo "Sorry, there was a problem uploading your file."; } ?> call a script from main page <div class="gallery"> <?php include "weddings/get.php" ?> </div> <div class="gallery"> <?php include "music/get.php" ?> </div> get.php displays links <?php include "db.php"; $cat = weddings; $q = "SELECT id, title, src, thumbsrc FROM $cat"; $result = $mysqli->query($q) or die(mysqli_error($mysqli)); if ($result) { echo "<ul id='photos'> \n"; while ($row = $result->fetch_object()) { $title = $row->title; $src = $row->src; $thsrc = $row->thumbsrc; $id = $row->id; echo "<a href='$src' class="lightbox" rel="$cat" title="$name - $title"><img src='$thsrc' id='$id' alt='$name' /></a>": } echo "</ul>"; } ?> I think i'm going along the right sort of path, but i'm not sure. Link to comment https://forums.phpfreaks.com/topic/247771-upload-file-make-thumb-insert-into-database-what-am-i-doing-wrong/ Share on other sites More sharing options...
litebearer Posted September 24, 2011 Share Posted September 24, 2011 Its early, haven't had 1st coffee, so didn't read your code yet - but what problem/error are you having? Link to comment https://forums.phpfreaks.com/topic/247771-upload-file-make-thumb-insert-into-database-what-am-i-doing-wrong/#findComment-1272321 Share on other sites More sharing options...
WebStyles Posted September 24, 2011 Share Posted September 24, 2011 you're grabbing the category with: $category = $_POST['cat']; but then you're trying to set the target directory with: $target = $cat."/"; it should be $target = $category."/"; (since $cat doesn't even exist.) If you turn on your error reporting, all these things will be obvious and easy to find out. Link to comment https://forums.phpfreaks.com/topic/247771-upload-file-make-thumb-insert-into-database-what-am-i-doing-wrong/#findComment-1272428 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.