Can you look at this code and tell me if it makes sense? I'm wondering if this isn't succeeding because I've of the use of the words thumbnail and newfilename, might be confusing the issue (or something else). Any clarity/feedback will be appreciated. if ($form_submitted == 'yes') { $allowedExts = array("gif", "jpeg", "jpg", "png"); $temp = explode(".", $_FILES["file"]["name"]); $extension = strtolower( end($temp) ); // in case user named file ".JPG" etc.!!! if ( $_FILES["file"]["size"] < 2000000 && in_array($extension, $allowedExts) ) { if ($_FILES["file"]["error"]!= 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br>"; } else { $length = 20; $randomString = substr(str_shuffle(md5(time())),0,$length); $newfilename = $randomString . "." . $extension; move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $newfilename); $sql = "INSERT INTO videos ( thumbnail ) VALUES ( '$thumbnail' )"; mysql_query($sql); $file_location = '<a href="http://www.---.com/upload/' . $thumbnail . '">' . $newfilename . '</a>'; } } else { echo "Invalid upload file"; } $description = $description . " \n " . $newfilename; } Code (markup):
yes it makes sense... but what if uploaded file is greater than 2000000 bytes or file extension is not allowed? you should give them a separate error message so you will know what was happening when upload failed..
where did you process your thumbnail? your thumbnail variable isn't defined before you insert it in database. you did not re size your uploaded image in your code. you should use thumbnail creator like http://phpthumb.sourceforge.net/ to create an actual thumbnail. or try to use this simple function to create thumbnail. http://webcheatsheet.com/php/create_thumbnail_images.php to save some space you can try also to generate thumbnail from original file once only when in demand
Thanks for your reply. Ultimately, I'm just trying to get an image link to show up with the video description on the page that displays the video and title/description, but I was told the link (to the image) had to be added to the db to make that happen. So I created a column in the 'videos' table (where title and description are stored) named 'thumbnail' to store the image link. So, as far as I know that, and please tell me if it's true, I'm don't really have a need to process a thumbnail?
you will have a problem with loading large images if you don't process your thumbnails. if you will upload it by yourself and not the user input then it will be no problem because you can re size it before you upload. to do that replace your $sql = "INSERT INTO videos ( thumbnail ) VALUES ( '$thumbnail' )"; mysql_query($sql); $file_location = '<a href="http://www.domain.com/upload/' . $thumbnail . '">' . $newfilename . '</a>'; with $sql = "INSERT INTO videos ( thumbnail ) VALUES ( '$newfilename' )"; mysql_query($sql); $file_location = '<a href="http://www.domain.com/upload/' . $newfilename. '">' . $newfilename . '</a>';
Thanks for that suggestion. After making the change you suggested, the image link now appears in the 'thumbnail' column (it wasn't before the change), that's progress(thanks). However, all the other columns in that row (except 'thumbnail' are NULL). I was hoping that the video, video title and video description AND image link would all appear in the same row, but currently the 'thumbnail' column is only filled in it's own row. I was hoping this upload video form (see attached) with the image upload in it, would all tie together in the db. Any additional help will be appreciated.