Jump to content

Help with displaying a successful hyperlink


Chrisj

Recommended Posts

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.
 
Link to comment
Share on other sites

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 by Frank_b
Link to comment
Share on other sites

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" />';
 
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.