glenelkins Posted July 2, 2006 Share Posted July 2, 2006 Quick couple of questions, using a file upload box on a form to upload an image...when the path is inserted into the database it misses the slashed (D:DocumentsFolderFolderFile.jpg) why??Second, when i then take this value from the database, how do i display it back in the file upload box, this <input type="file" name="file" value="<? echo $valuefrom_db; ?>"> does not seem to display itcheers Quote Link to comment https://forums.phpfreaks.com/topic/13461-image-path-into-database/ Share on other sites More sharing options...
Drumminxx Posted July 2, 2006 Share Posted July 2, 2006 [quote]Quick couple of questions, using a file upload box on a form to upload an image...when the path is inserted into the database it misses the slashed (D:DocumentsFolderFolderFile.jpg) why??[/quote]post some code please.[quote]Second, when i then take this value from the database, how do i display it back in the file upload box, this <input type="file" name="file" value="<? echo $valuefrom_db; ?>"> does not seem to display it[/quote]due to the way the file field works you can't set its value. your best bet is what I did just echo the name of the current file and right next to it give the user a file box to upload another file. Quote Link to comment https://forums.phpfreaks.com/topic/13461-image-path-into-database/#findComment-52022 Share on other sites More sharing options...
redarrow Posted July 2, 2006 Share Posted July 2, 2006 my example ok<? session_start();if(!$userfile=="none"){echo"No file specified<br><br><a href='members_upload_picture_form.php'>Please use this link</a>";exit;}// check if user has a picture if so echo message and link$db=mysql_connect("localhost" ,"xxx","xxx");mysql_select_db("promotor",$db);$query="select * from members_picture_uploads where name='$name' and id='$id'";$result=mysql_query($query);while($row=mysql_fetch_assoc($result)) {if($row["userfile_name"]=1) {echo "<b>sorry you have a picture already</b>";echo"<br><br><a href='members_update_picture_form.php'>Please use this link</a>";exit;} }// file upload information$uploaddir ="members_uploads/";$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);//set a date sent $date_sent=date("d-m-y");// set a mime valadating $blah = getimagesize($userfile);$type = $blah['mime'];$width = $blah[0];$size = $blah[2]=$_FILES['userfile']['size'];// valadate siz and typeif($size <= 50000) {if($type) {// if file correct let file throw and into the folderif(move_uploaded_file($_FILES['userfile']['tmp_name'],$uploadfile)) {$userfile_name=addslashes($userfile_name);$query="insert into members_picture_uploads values('$id','$name','$date_sent','$userfile_name')";$result=mysql_query($query);// say thank you if the user has a valid file.echo "file uploaded thank you<br>";exit;}// echo link for valadating pic}else{echo "Wrong file type .jpg or .gif thank you <br><br> <a href ='members_upload_picture_form.php'>Pleae try agin</A>";}//echo link for valadating file size}else{echo "Wrong file size 50000 bytes only<br><br> <a href ='members_upload_picture_form.php'>Pleae try agin</A>";}?> Quote Link to comment https://forums.phpfreaks.com/topic/13461-image-path-into-database/#findComment-52025 Share on other sites More sharing options...
glenelkins Posted July 2, 2006 Author Share Posted July 2, 2006 hi, thanks for the reply, here is some code that inserts the image filename, iv never had this problem before.FIRST BIT CAPTURES THE USER ACTION (REGISTER) SECOND IS THE FUNCTION[code]/* REGISTER START */if ($action == "register") { // Register if ($yourbest -> CheckRegPassMatch ($_POST['pword'],$_POST['rpword'])) { // Passwords fields match if ($reg = $yourbest -> Register ($_POST['fname'],$_POST['sname'],$_POST['title'],$_POST['comp'],$_POST['pno'],$_POST['email'],$_POST['uname'],$_POST['pword'],$_POST['image'])) { // Registration success $header_url = "Location: register_confirmation.php"; header ($header_url); break; } else { // Registration failed echo $reg; break; } } else { // Passwords do not match $header_url = "Location: RegisterForm.php?message=The Password Fields Do Not Match!"; header ($header_url); break; }}/* REGISTER END */[/code][code]function Register ($fname,$sname,$title,$company,$phoneno,$email,$username,$password,$image) { $sql = "INSERT INTO users VALUES ('','$fname','$sname','$title','$company','$phoneno','$email','$username','$password','$image')"; $result = mysql_query($sql); if ($result) { // Success return (true); break; } else { // Fail return (mysql_error()); break; }}[code][/code][/code] Quote Link to comment https://forums.phpfreaks.com/topic/13461-image-path-into-database/#findComment-52028 Share on other sites More sharing options...
glenelkins Posted July 2, 2006 Author Share Posted July 2, 2006 I figured it! im such a dumb ass. Iv been putting the filename from the uplaod box into the database rather than the actual online path, due to the fact i have not included the image upload,resize function i have written! Quote Link to comment https://forums.phpfreaks.com/topic/13461-image-path-into-database/#findComment-52030 Share on other sites More sharing options...
Drumminxx Posted July 2, 2006 Share Posted July 2, 2006 ::) it happens sometimes :o Quote Link to comment https://forums.phpfreaks.com/topic/13461-image-path-into-database/#findComment-52037 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.