Jump to content

Image Path Into Database


glenelkins

Recommended Posts

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 it

cheers
Link to comment
Share on other sites

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

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 type

if($size <= 50000) {

if($type) {

// if file correct let file throw and into the folder

if(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>";
}

?>
Link to comment
Share on other sites

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

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!
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.