Chrisj Posted October 16, 2014 Share Posted October 16, 2014 I'm using a templated PHP script where the (video) Upload Form info (title, description, etc.) is displayed (after the upload) on a page below the video. I added a basic image-uploader to the Form, and some code that, via the Form, adds the 'user_id' to the beginning of the file name, for example, people.png uploaded (by user 9) becomes the new file name: 9people.png, which gets uploaded into the /upload/ folder, and stores that new file name into a db table called 'videos', into a column named 'thumbnail'. I'm looking for guidance with making a successful hyperlink(to the image) appear where the Upload Form info is displayed. This is the results.php page code that corresponds with the html page (inner_results.htm): <?php include_once ('classes/config.php'); include_once ('classes/sessions.php'); include_once ('classes/functions.inc.php'); $page_title = $site_name; $submitted = $_POST['submitted']; $which_one = mysql_real_escape_string($_GET['load']); $limit = 20; $keyword = $_SESSION['searched']; // this is per each template from config.inc.php advanced config settings $page_display_small_width = $config['general_medium_thumb_width']; // 80 $member_credits = get_member_credits($user_id); if ($user_id != "") { $inner_template1 = "themes/$user_theme/templates/inner_results.htm"; }else{ $show_login = 1; $inner_template1 = "themes/$user_theme/templates/inner_signup_form.htm"; } // FUNCTIONS function getUsername($id) { $sql1 = "SELECT * FROM member_profile WHERE $query1 = mysql_query($sql1) or DIE(mysql_error()); $result = mysql_fetch_array($query1); return $result['user_name']; } function getVidTitle($id) { $sql1 = "SELECT * FROM videos WHERE indexer = $id"; $query1 = mysql_query($sql1) or DIE(mysql_error()); $result = mysql_fetch_array($query1); return $result['title']; } ?> Can you make a suggestion, or give me an idea, as to what I might add to results.php (and inner_results.php) in order to display a successful hyperlink to the image that was uploaded with the video? Any help will be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/291862-help-with-displaying-a-successful-hyperlink/ Share on other sites More sharing options...
Frank_b Posted October 16, 2014 Share Posted October 16, 2014 (edited) what a mess. a user_id at the beginning of a filename... What if my filename starts with a number. Let's say 12hours.jpg. and my user id is 5. Then the filename would be 512hours.jpg. Lucky for user number 512, he just got a free picture. Then number two: is there a limit for one upload per user? what if the user wants to upload more then one? where are you going to store that in your database? I can make one suggestion i am affraid: stop coding and buy yourself a book! Edited October 16, 2014 by Frank_b Quote Link to comment https://forums.phpfreaks.com/topic/291862-help-with-displaying-a-successful-hyperlink/#findComment-1493933 Share on other sites More sharing options...
QuickOldCar Posted October 16, 2014 Share Posted October 16, 2014 I can make one suggestion i am affraid: stop coding and buy yourself a book! Ouch, these are the people we are supposed to be helping the most, the ones that need it. 1 Quote Link to comment https://forums.phpfreaks.com/topic/291862-help-with-displaying-a-successful-hyperlink/#findComment-1493937 Share on other sites More sharing options...
jcbones Posted October 16, 2014 Share Posted October 16, 2014 First, you should be storing the user_id and possibly the username in your session data. Therefore, you will not have to grab that each time you want to query for more data. Just use the session for that info. Secondly, Frank_b is right in a sense that there is no need to associate user_id's with individual pics. Just use the database to relate the pic back to an individual user. With a table of pic names, you can relate much more than one pic to the user. To get the image to show up on the page, you just use a standard HTML img element. I always check to make sure the file exists first. $file = '/home/me/www/images/' . $row['filename']; if(file_exists($file)) { $file = $row['filename']; } else { $file = 'default.jpg'; } echo '<img src="http://mysite.com/images/' . $file . '" alt="No image" />'; Quote Link to comment https://forums.phpfreaks.com/topic/291862-help-with-displaying-a-successful-hyperlink/#findComment-1493942 Share on other sites More sharing options...
Chrisj Posted October 17, 2014 Author Share Posted October 17, 2014 Thanks for your replies. When I add your "standard HTML img element" <?php $file = '/home/me/www/images/' . $row['filename']; if(file_exists($file)) { $file = $row['filename']; } else { $file = 'default.jpg'; } echo '<img src="http://mysite.com/images/' . $file . '" alt="No image" />'; ?> I see this part of that code on the page '; ?> Help please. Quote Link to comment https://forums.phpfreaks.com/topic/291862-help-with-displaying-a-successful-hyperlink/#findComment-1494022 Share on other sites More sharing options...
Frank_b Posted October 17, 2014 Share Posted October 17, 2014 can you show the html of this part of your page? I mean the source of your HTML page, you can choose to see the source in your browser.. Quote Link to comment https://forums.phpfreaks.com/topic/291862-help-with-displaying-a-successful-hyperlink/#findComment-1494058 Share on other sites More sharing options...
Chrisj Posted October 18, 2014 Author Share Posted October 18, 2014 Thanks for your reply, but I'm not sure if providing the source is going to help here. It isn't my script I'm just trying to tweak it, to get this one function working. But, what I actually think might help, please, is to know if I add in a function, into the code above, like this example: function getFilename($id) { $sql1 ="SELECT filename FROM videos WHERE indexer = '".$id."'"; $query1 = mysql_query($sql1) or DIE(mysql_error()); $result = mysql_fetch_array($query1); return $result['filename']; } Will it correspond with this upload Form code - where the image file is chosen and stored: $allowedExts = array("gif", "jpeg", "jpg", "pdf", "png"); $temp = explode(".", $_FILES["file"]["name"]); $extension = strtolower( end($temp) ); if (!in_array($extension,$allowedExts)) { echo ("Error - Invalid File Name"); } $length = 20; $newfilename = $_SESSION['user_id'].$_FILES["file"]["name"]; $thumbnail = $newfilename; move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $thumbnail); $sql = "INSERT INTO videos ( filename ) VALUES( '$thumbnail' )"; mysql_query($sql); $file_location = '<a href="http://www.--.com/upload/' . $thumbnail . '">' . $thumbnail . '</a>'; Any additional help will be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/291862-help-with-displaying-a-successful-hyperlink/#findComment-1494063 Share on other sites More sharing options...
jcbones Posted October 18, 2014 Share Posted October 18, 2014 I'm starting to think this code is provided as some type of school work. We have seen this exact, or nearly exact, code a dozen times in the past week. Quote Link to comment https://forums.phpfreaks.com/topic/291862-help-with-displaying-a-successful-hyperlink/#findComment-1494089 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.