hi i have already typed my code below. the database is saving the path of image but it is not displaying the image . where could i be wrong?
<div class="profile"> <?php if (isset($_FILES['profile']) === true) { if (empty($_FILES['profile']['name']) === true) { echo 'Please choose a file'; } else { $allowed = array('jpg', 'jpeg', 'gif', 'png'); $file_name = $_FILES['profile']['name']; $file_extn = strtolower(end(explode('.', $file_name))); $file_temp = $_FILES['profile']['tmp_name']; if (in_array($file_extn, $allowed) === true) { ///upload file. change_profile_image($session_user_id, $file_temp, $file_extn); } else { echo 'incorrect file type. Allowed formats: '; echo implode(', ', $allowed); } } } if (empty($user_data['profile']) === false) { echo '<img src"', $user_data['profile'], '" alt="', $user_data['first_name'], '\'s">'; } ?> <form action="" method="post" enctype="multipart/form-data"> <input type="file" name="profile"> <input type="submit"> </form> </div> and the function change_profile_image I am calling is below:
function change_profile_image($user_id, $file_temp, $file_extn) { $file_path = 'images/profile/' . substr(md5(time()), 0, 10) . '.' . $file_extn; //echo $file_path; move_uploaded_file($file_temp, $file_path); mysql_query("UPDATE `users` SET `profile` = '" . mysql_real_escape_string($file_path) . "' WHERE `user_id` = " . (int) $user_id); } the database is saving the image path but not displaying the image on the webpage.
echo '<img src"', $user_data['profile'], '"should beecho '<img src="', $user_data['profile'], '"for a start.echo '<img src"', $user_data['profile'], '"should beecho '<img src="'.$user_data['profile'].'"===expression fromissetandempty. Those functions always return boolean value. Yo can simply writeif(isset($whatever)){}. This is a suggestion and not the answer.$user_datavariable?