Jump to content

Archived

This topic is now archived and is closed to further replies.

wwfc_barmy_army

[Solved]Image Upload to database?

Recommended Posts

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) :

[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";
}[/code]

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.

Share this post


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

[code]
$sql = "INSERT INTO yourtable (target) values ('$target')";
mysql_query($sql);
[/code]

Share this post


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

Share this post


Link to post
Share on other sites
Yes you can do that just add this code before inserting into database
[code]
$targettodb = str_replace("../","",$target);
[/code]

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

Share this post


Link to post
Share on other sites

×

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.