473,387 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Storing Image Path in mySQL field

I made a PHP form to add data to the mysql database and now I wan't to add photos (not to mysql db because I heard that's not a good ideea, so...) and list it with rest of the info from db I`v inserted with.

I made a upload form, but I don't know how to rename the file`s I upload, and make a new folder for each time I upload data + photo, and than list photo from folder with the rest of the data I`v inserted.


In other words...

New data added from form to db
Name, Age, Email, Description, Photo1, Photo2, Photo3.
Upload to db and list it when necessary.

Please help...
Best regards
Oct 29 '11 #1
5 2398
zorgi
431 Expert 256MB
To rename files you can use rename() function: http://php.net/manual/en/function.rename.php

Once you have your files referenced in your database, retrieve rows of data using MySql SELECT statement http://dev.mysql.com/doc/refman/5.0/en/select.html
Oct 29 '11 #2
I did rename the files, but how I make referenced in my database?
thank you
Oct 30 '11 #3
zorgi
431 Expert 256MB
Same way as you would add anything into the database. I usually insert only unique name of the file. Of course you can store path to the file if you prefer that way.
Oct 30 '11 #4
How can I upload 3-4 photos without copy-paste the entire code and how do I make references of new photos uploaded to insert in the db with the new data enter from 'inputImobil' and 'inputDescriere'?
Please help

This is the code that I`v combined for insert data to db and upload 1photo.


<?php

include 'connection.php';

$imobil = $_POST[inputImobil];
$desc = $_POST[inputDescriere];



define ("MAX_SIZE","1000");
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
$errors=0;


if(isset($_POST['submit'])) {
$image=$_FILES['image']['name'];
if ($image) {
$filename = stripslashes($_FILES['image']['name']);
$extension = getExtension($filename);
$extension = strtolower($extension);
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
{
$newrecord1 = "<h1>Unknown extension!</h1>";
$errors=1;
}
else
{
$size=filesize($_FILES['image']['tmp_name']);
$image_name=time().'.'.$extension;
$newname="upload/".$image_name;
$copied = copy($_FILES['image']['tmp_name'], $newname);

}}}
if(isset($_POST['submit']) && !$errors)
{
$newrecord2 = "<h1>File Uploaded Successfully! Try again!</h1>";
}

if(!$_POST['submit']) {
$newrecord3 = "Completeaza formularul";

}else{
mysql_query("INSERT INTO vanzare (`ID`,`Imobil`,`Descriere`)
VALUES(NULL,'$imobil','$desc')") or die(mysql_error());
$newrecord4 = "Adaugare reusita!";
header('Location: new5.php');
}

?>
Oct 30 '11 #5
I`v insert the patch to db like this...

mysql_query("INSERT INTO vanzare (`ID`,`Imobil`,`Descriere`,`Telefon`)
VALUES(NULL,'$imobil','$desc','$newname')") or die(mysql_error());



How can I add 3-4 photos without double the code...
And how do I select the table where to add the data.

If select value="1" add data to table1 and if select value="2" add data to table2... All data from all fields.... (inputImobil, inputDescriere, Photo1, Photo2, etc...)
Oct 31 '11 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Kevin Vogler | last post by:
I have a subdirectory with it's own images folder. All the image paths in the pages in the sub directory are "image/image.jpg" When I Response.Redirect to a page in the subdirectory the images...
9
by: TJS | last post by:
when using a relative image path const imgDir = "_images/divisions/" the relative path is converted to a physical path in an img tag as <img src="c:\app\_images\divisions\mypicture.gif"> ...
10
by: John Smith | last post by:
I know that uploading an image to a database has been covered, oh, about 3 trillion times. However, I haven't found anything covering uploading to a MySQL database with .net. Please don't...
2
by: Jester | last post by:
I'm fairly new to asp.net. What is the syntax for the string to pull and image path from a DB and display that image based on the given path? I am trying to stay away from actually storing images...
3
by: Maverick | last post by:
Hi, I have to give a browse button and you will be able to browse and pick the image path instead of typing it out. One more requirement will be the image will be residing on a shared machine in...
1
by: jarremw | last post by:
hello all, i am making a database to hold some scanned pdf's so i was wondering how would i go about saving them in the mysql database? would i put the file in the database or just link to it? so if...
4
by: foss | last post by:
HI all, I am able to upload the image as blob to mysql. but while displaying the image i cant display it properly . The code used for uploading image to mysql inserts data into mysql table.The...
2
by: hiranmaie | last post by:
I am having the problem with the image path. I am using a master page and the reference to the image in web content page which is not working properly. It shows Done, with errors on page error. If I...
2
by: jewellman | last post by:
Hello. I have been reading over some posts that deal with my issue and although I couldn't get my issue to work I did read some very good information. I have created a mySQL table that I will use...
1
by: santhanalakshmi | last post by:
hi, Please tell me ,how to insert an image in mysql ? for example ,my image is in the c drive under the image folder. We can use "BLOB datatype" for storing of ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.