Hi all, i have a script which uploads images to the server, and sends attributes of car name, car make, car registration to the database, i need now to be able to store some kind of link to the image stored.
Any help would be great, thanks.
Here is my upload code:
<form enctype="multipart/form-data" action="upload.php" method="post" name="upload_file">
<input type="hidden" name="MAX_FILE_SIZE" value="5000000">
Please enter the car make: <input name=mymake><br>
Please enter the car model: <input name=mymodel><br>
Please enter the car registration: <input name=myreg><br>
Please select an image to upload:
<input name="userfile" type="file"></br>
<input type="submit" value="upload" name="file_uploaded">
</form>
Here is my code which places the details into the database and places the image on the server.
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="root"; // Mysql password
$db_name="test"; // Database name
$tbl_name="reff"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "root", "root")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$mymake=$_POST['mymake'];
$mymake=$_POST['mymodel'];
$myreg=$_POST['myreg'];
$userfile=$_POST['userfile'];
mysql_select_db("test");
$result = mysql_query("INSERT INTO reff (make, model, registration, imgdata)
VALUES ('$_POST[mymake]', '$_POST[mymodel]', '$_POST[myreg]', '$_POST[userfile]')");
if (is_uploaded_file($_FILES['userfile']['tmp_name']))
{
$file_realname = $_FILES['userfile']['name'];
copy($_FILES['userfile']['tmp_name'], realpath("upload").trim($file_realname));
}
else
{
echo "<b><font color=red>No file uploaded.</font></b><BR>No file available or file too big to upload.";
}
echo $file_realname;
?>