Jump to content


Photo

[Solved]Image Upload to database?


  • Please log in to reply
5 replies to this topic

#1 wwfc_barmy_army

wwfc_barmy_army
  • Members
  • PipPipPip
  • Advanced Member
  • 320 posts

Posted 01 October 2006 - 08:46 AM

Hi again guys.

I'm here with another problem i have :)

Ok, well i have a screenshot uploader on the admin of my site, and currently it uploads fine, although we need it add the link of where it's uploaded to, to the database but i'm not sure how to go about this (i'm still rather new to php), this is the code that uploads the image(a normal browse input box is further up the code) :

   //Writes the screenshot to the server
if(move_uploaded_file($_FILES['screenshot']['tmp_name'], $target))
{

//Tells you if its all ok
echo "The file ".basename( $_FILES['uploadedfile']['name']). " has been uploaded.";
}
else {

//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}

   echo "<p>Site, '$name', has now been added";
}

Any advice on how i could get it to add it to the screenshot field in the site table? And also i would like to know if it's possible to add more than one screenshot in the seperate screen? Any advice, links, tutorials or code is appricated.

Thanks for all your advice.

Peter.


#2 wwfc_barmy_army

wwfc_barmy_army
  • Members
  • PipPipPip
  • Advanced Member
  • 320 posts

Posted 01 October 2006 - 06:44 PM

*Bump* :)

#3 ponsho

ponsho
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 01 October 2006 - 07:06 PM

I dont know if i understood what you're trying to do, if its just to save the address of the screenshot your uploading into the database, just insert your $target variable into it.

$sql = "INSERT INTO yourtable (target) values ('$target')";
mysql_query($sql);


#4 wwfc_barmy_army

wwfc_barmy_army
  • Members
  • PipPipPip
  • Advanced Member
  • 320 posts

Posted 01 October 2006 - 07:55 PM

Hello.

That was pretty much what i wanted :) But one thing, currently the images are being entered into the database as:
"../images/screenshots/image.jpg"

But i want it as "images/screenshots/image.jpg", is there any way of doing this as when i try to display the image elsewhere on the site (not in the admin area) it messes up and i think it's because off the "../" in front of it.

Can i do that?

Thanks.

Peter.

#5 ponsho

ponsho
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 02 October 2006 - 04:58 AM

Yes you can do that just add this code before inserting into database
$targettodb = str_replace("../","",$target);

So now the variable youre going to insert its the $targettodb

#6 wwfc_barmy_army

wwfc_barmy_army
  • Members
  • PipPipPip
  • Advanced Member
  • 320 posts

Posted 02 October 2006 - 08:17 AM

Brilliant! Thank for your help ponsho! :)

Peter.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users