Skipjackrick Posted February 22, 2008 Share Posted February 22, 2008 Hi again, In my database, (when I upload images through an html form) my URL's to images are stored in the following fashion: /home/ectackle/public_html/images/image-name.jpg Okay, now I am trying to create a page that allows the user to view the image they uploaded. Using the following code, everything works great except the image won't display. When I check the URL to the image it shows this http://www.ectackle.com/home/ectackle/public_html/images/image-name.jpg If I could just get rid of the text in red. I'd be golden. Is there an alternate way to display my image or a way to make the /home/ectackle/public_html/images/image-name.jpg format work to display my image???????? <?php $query_image = "SELECT filename, team_id, MAX(date) FROM image GROUP BY team_id ORDER BY MAX(date)DESC LIMIT 1"; $image_result = mysql_query($query_image) or die(mysql_error()); while($row = mysql_fetch_array($image_result)) { $imagename = $row['filename']; $imagedate = $row['MAX(date)']; $display_image .=<<<EOD <h2><div align="center"><img src="$imagename"></div></h2> EOD; } print $display_image; ?> Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted February 22, 2008 Share Posted February 22, 2008 only store the image name, not the full path. tack the path on as needed. Quote Link to comment Share on other sites More sharing options...
Skipjackrick Posted February 22, 2008 Author Share Posted February 22, 2008 only store the image name, not the full path. tack the path on as needed. Sounds like an easy fix. I grabbed the upload form code from someone else. I can't find the image name in this code. Its a bit over my head. Can you find the variable that would be the filename only? Would it happen to be this.............. $now.'-'.$_FILES[$fieldname]['name'] <?php // filename: upload.processor.php // first let's set some variables // make a note of the current working directory, relative to root. $directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']); // make a note of the directory that will recieve the uploaded files $uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . 'uploaded_files/'; // make a note of the location of the upload form in case we need it $uploadForm = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'upload.form.php'; // make a note of the location of the success page $uploadSuccess = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'index.php'; // name of the fieldname used for the file in the HTML form $fieldname = 'file'; // Now let's deal with the upload // possible PHP upload errors $errors = array(1 => 'php.ini max file size exceeded', 2 => 'html form max file size exceeded', 3 => 'file upload was only partial', 4 => 'no file was attached'); // check the upload form was actually submitted else print form isset($_POST['submit']) or error('the upload form is neaded', $uploadForm); // check for standard uploading errors ($_FILES[$fieldname]['error'] == 0) or error($errors[$_FILES[$fieldname]['error']], $uploadForm); // check that the file we are working on really was an HTTP upload @is_uploaded_file($_FILES[$fieldname]['tmp_name']) or error('not an HTTP upload', $uploadForm); // validation... since this is an image upload script we // should run a check to make sure the upload is an image @getimagesize($_FILES[$fieldname]['tmp_name']) or error('only image uploads are allowed', $uploadForm); // make a unique filename for the uploaded file and check it is // not taken... if it is keep trying until we find a vacant one $now = time(); while(file_exists($uploadFilename = $uploadsDirectory.$now.'-'.$_FILES[$fieldname]['name'])) { $now++; } // now let's move the file to its final and allocate it with the new filename @move_uploaded_file($_FILES[$fieldname]['tmp_name'], $uploadFilename) or error('receiving directory insuffiecient permission', $uploadForm); // If you got this far, everything has worked and the file has been successfully saved. // We are now going to redirect the client to the success page. header('Location: ' . $uploadSuccess); Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted February 22, 2008 Share Posted February 22, 2008 yes, you've got it. Quote Link to comment Share on other sites More sharing options...
Skipjackrick Posted February 22, 2008 Author Share Posted February 22, 2008 yes, you've got it. Hmmm...I got a syntax error from it. Am I putting the value in correctly? You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'name']','22Feb08','1')' at line 1 $q = "INSERT INTO image (image_id,filename,date,team_id) VALUES ('NULL','now.'-'.$_FILES[$fieldname]['name']','".date(dMy)."','1')"; $s = mysql_query($q, $conn); Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted February 22, 2008 Share Posted February 22, 2008 i'd build the filename string outside the sql first: $filename = $now.'-'.$_FILES[$fieldname]['name']; $q = "INSERT INTO image (image_id,filename,date,team_id) VALUES ('NULL','$filename','".date(dMy)."','1')"; Quote Link to comment Share on other sites More sharing options...
Skipjackrick Posted February 22, 2008 Author Share Posted February 22, 2008 i'd build the filename string outside the sql first: $filename = $now.'-'.$_FILES[$fieldname]['name']; $q = "INSERT INTO image (image_id,filename,date,team_id) VALUES ('NULL','$filename','".date(dMy)."','1')"; DOH! You're smart. Thanks! Quote Link to comment Share on other sites More sharing options...
Skipjackrick Posted February 22, 2008 Author Share Posted February 22, 2008 Darn it!! It gave me two entries into the database. The first entry was $now and the second entry was -name.jpg $filename = $now.'-'.$_FILES[$fieldname]['name']; $q = "INSERT INTO image (image_id,filename,date,team_id) VALUES ('NULL','$filename','".date(dMy)."','1')"; Quote Link to comment Share on other sites More sharing options...
Skipjackrick Posted February 22, 2008 Author Share Posted February 22, 2008 AHAHAHA!! Nevermind. I found my error. I need to review my script before posting. I could have saved precious time!!!!!!!! THANKS TO ALL!!!!!!! Quote Link to comment 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.