squiblo Posted July 29, 2009 Share Posted July 29, 2009 ok, what i am doing is, uploading an image and then using it as a profile image, i have successfully uploaded an image and the image is now in the database, but when i try getting the image from the database and trying to view it, the image is not being shown but area where the image should be is marked with the currupt file icon. i do not understand what could be wrong, here are all my scripts being used: upload.php <?php session_start(); include("checklogin.php"); $_SESSION['myusername']; $username = $_SESSION['myusername']; if ($_POST['submit']) { //get file attributes $name = $_FILES['myfile']['name']; $tmp_name = $_FILES['myfile']['tmp_name']; if ($name) { //start upload process $location = dirname(__FILE__)."/profileimages/$name"; move_uploaded_file($tmp_name,$location); $query = mysql_query("UPDATE members SET imagelocation='$location' WHERE username='$username'") or die(mysql_error()); die("Your profile picture have been upload! <a href='view.php'>View</a>"); } else die("Please select a file!"); } echo "Welcome, ".ucwords(strtolower($_SESSION['myusername']))."!<p>"; echo "Upload your image: <form action='upload.php' method='POST' enctype='multipart/form-data'> File: <input type='file' name='myfile'> <input type='submit' name='submit' value='Upload'> </form> "; ?> checklogin.php <?php $host="localhost"; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name="members"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); if(isset($_POST['Login'])){ // username and password sent from form $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); //$_SESSION['myusername']=$dbusername; $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "profile.php" session_register("myusername"); session_register("mypassword"); header("location:profile.php"); } else { header("location: http://www.squiblo.com/retrylogin.php"); } } ?> view.php <?php session_start(); include("checklogin.php"); $username = $_SESSION['myusername']; $query = mysql_query("SELECT * FROM members WHERE username='$username'"); if (mysql_num_rows($query)==0) die("User not found!"); else { $row = mysql_fetch_assoc($query); $location = $row['imagelocation']; echo "<img src ='$location' width='700' height='700'>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/167883-solved-cannot-see-image/ Share on other sites More sharing options...
squiblo Posted July 29, 2009 Author Share Posted July 29, 2009 when i echo out my file location i get: /customers/squiblo.com/squiblo.com/httpd.www/profileimages/homepage-pic.jpeg the reason i think i get this long code is becuase im using a sharing hosting website (one.com), or am i being misleaded? Quote Link to comment https://forums.phpfreaks.com/topic/167883-solved-cannot-see-image/#findComment-885484 Share on other sites More sharing options...
lonewolf217 Posted July 29, 2009 Share Posted July 29, 2009 check two things 1) what is the location that is in the database 2) is the file actually at the location that you want it to be in ? I am a little hazy on file uploads, but I do not understand this part <?php //get file attributes $name = $_FILES['myfile']['name']; $tmp_name = $_FILES['myfile']['tmp_name']; // <----------- where is 'tmp_name' coming from ?? // and then later move_uploaded_file($tmp_name,$location); // <------- are you sure it is moving the file where you want it to be ? Quote Link to comment https://forums.phpfreaks.com/topic/167883-solved-cannot-see-image/#findComment-885489 Share on other sites More sharing options...
TeNDoLLA Posted July 29, 2009 Share Posted July 29, 2009 $_FILES['myfile']['tmp_name'] is the name of the file that was uploaded in the server. $_FILES['myfile']['''name'] is just the name of the file that was in the clients side and it does not exist in the server. Quote Link to comment https://forums.phpfreaks.com/topic/167883-solved-cannot-see-image/#findComment-885494 Share on other sites More sharing options...
squiblo Posted July 29, 2009 Author Share Posted July 29, 2009 this is the location of the file shown in the database: /customers/squiblo.com/squiblo.com/httpd.www/profileimages/Autumn Leaves.jpg i got help with this script so i also do not understand parts, im quiet new to php. the process is, upload the image (in my case to ftp) > then get image from ftp to sql > then show image from sql on webpage. (i think) Quote Link to comment https://forums.phpfreaks.com/topic/167883-solved-cannot-see-image/#findComment-885496 Share on other sites More sharing options...
squiblo Posted July 29, 2009 Author Share Posted July 29, 2009 im am using a shared hosting website, will this make a difference? Quote Link to comment https://forums.phpfreaks.com/topic/167883-solved-cannot-see-image/#findComment-885509 Share on other sites More sharing options...
lonewolf217 Posted July 29, 2009 Share Posted July 29, 2009 i think the problem lies here <?php $location = dirname(__FILE__)."/profileimages/$name"; from here http://us2.php.net/manual/en/function.dirname.php it looks like this will get the pathname of the page that is currently loaded, or "/customers/squiblo.com/squiblo.com/httpd.www". You then append the path that you do want to the end of this, bringing you to the monstrosity in your database. do you happen to know what the correct path of the file SHOULD be ? perhaps then we can see exactly where the problem is, but right now I do not know what your expected directory structure is Quote Link to comment https://forums.phpfreaks.com/topic/167883-solved-cannot-see-image/#findComment-885515 Share on other sites More sharing options...
squiblo Posted July 29, 2009 Author Share Posted July 29, 2009 i think i expect the correct path of the file to be something like... "www.domain.com/profileimages/(name of the image)" Quote Link to comment https://forums.phpfreaks.com/topic/167883-solved-cannot-see-image/#findComment-885546 Share on other sites More sharing options...
squiblo Posted July 29, 2009 Author Share Posted July 29, 2009 ive tried echoing everything but, everything seems fine, this doesnt seem to be working, is there anyone that could show me a script that works for them? or can see what is wrong with mine? Quote Link to comment https://forums.phpfreaks.com/topic/167883-solved-cannot-see-image/#findComment-885579 Share on other sites More sharing options...
lonewolf217 Posted July 29, 2009 Share Posted July 29, 2009 try just opening "www.domain.com/profileimages/(name of the image)" from your browser and see if it shows up properly. If it does, I would suggest taking out the dirname(__FILE__) from your $location variable. If it doesn't, you need to check what the actual path to the file is Quote Link to comment https://forums.phpfreaks.com/topic/167883-solved-cannot-see-image/#findComment-885584 Share on other sites More sharing options...
squiblo Posted July 29, 2009 Author Share Posted July 29, 2009 this is the image that i am uploading, i can view the image when i type this into my url: www.squiblo.com/profileimages/Autumn Leaves.jpg Quote Link to comment https://forums.phpfreaks.com/topic/167883-solved-cannot-see-image/#findComment-885591 Share on other sites More sharing options...
lonewolf217 Posted July 29, 2009 Share Posted July 29, 2009 and what happens when you make the modification to $location in your script ? You will probably also have to manually update what is already in your database <?php $location = "/profileimages/$name"; Quote Link to comment https://forums.phpfreaks.com/topic/167883-solved-cannot-see-image/#findComment-885593 Share on other sites More sharing options...
squiblo Posted July 29, 2009 Author Share Posted July 29, 2009 that you very much, im very gratefully, i feel like opening my wallet and giving you all i have . Quote Link to comment https://forums.phpfreaks.com/topic/167883-solved-cannot-see-image/#findComment-885598 Share on other sites More sharing options...
lonewolf217 Posted July 29, 2009 Share Posted July 29, 2009 i wouldn't turn that down if its solved, dont forget to click the Topic Solved button ! Quote Link to comment https://forums.phpfreaks.com/topic/167883-solved-cannot-see-image/#findComment-885600 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.