Jump to content

Store image path in mysql


Jamied_uk

Recommended Posts

hi i want to store url to images in database for logged in users (where id = $id)

 

and recall the image hopefully using

---------------------

<img src="<?php echo row['link']; ?>" /> or similar and need help with the sql update string any ideas please help i been stuck with this for some time and now decided to ask around in this forum for help, please help if you can.

Link to comment
Share on other sites

hi i want to store url to images in database for logged in users (where id = $id)

 

and recall the image hopefully using

---------------------

<img src="<?php echo row['link']; ?>" /> or similar and need help with the sql update string any ideas please help i been stuck with this for some time and now decided to ask around in this forum for help, please help if you can.

 

Again, don't necro old threads, create a new thread in the proper forum with your question.

Link to comment
Share on other sites

Its very simple to store the image path into your mysql database.

 

please consider this example.

 


<?php

//getting the filename of the image file.
$filename = $_FILES["image"]["name"];

//directory name to be stored.
$path = "data/mydata";

//uploading the image file with the image file name into the directory.
if(move_uploaded_file($_FILES["image"]["tmp_name"],$path."/".$filename) {

//if the image is stored success into the directory then we are going to store into database.

//the real path with the filename.

$mysql_path = $path."/".$filename;

//sql query to be executed.
$sql = "INSERT INTO `tablename`(`filename`,`path`) VALUES ('$filename','$mysql_path')";

//executing the query.
if(mysql_query($sql)) {

echo 'path inserted into database';

}

else {

echo 'path not inserted into database';

}

}

else {

echo 'file not uploaded';

}

?>

 

 

 

Link to comment
Share on other sites

thank you i will try it now, just gotta edit some values, also is this line i changed ok my files are stored in /pics/

 

$path = "/pics/";

 

 

I assume this is ok but will now check, reason i ask is because i also assume i do not have to change this line,

$mysql_path = $path."/".$filename;

 

 

thanks for your reply again it was helpful.

 

just checked the page but it is blank im missing the form part for file and submit, can you supply this as this is part the reason i have had issues because php and mysql parts are hard to find together for this task, i new the concept was easy but only if its all there.

Link to comment
Share on other sites

yes you are right because

 


//this variable contains only the directory path which the image file to be stored. So you don't need to put the "/" end of the path.
$path = "/pics";

//this variable contains the joining of file name with its directory path to get the real path of the image file. So you don't have to edit this.
$mysql_path = $path."/".$filename;

//if you echo this line.

echo $mysql_path;

//the result will be.

/pics/somefile.jpg

 

Link to comment
Share on other sites

because my friend it is better to have all the required info all on one page not throughout multiple posts, this may not be good for everyone but is most sensible and keeps posts to a minimum when you only reply with a question or an answer, not just for sake of posting.

Link to comment
Share on other sites

  • 2 years later...

@josephbupe, programming help forums are not for getting people to write code for you. they are for getting help with code you are writing. if it's beyond your programming skills to do something that you want, you will need to hire someone to do it for you.

 

if you do have your own programming that you have written and need help with, start your own thread for it. topic locked.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • 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.