amir4oracle
Programmer
To upload/save image on MySQL DB I created the following table:
CREATE TABLE test_pic
( name varchar (30), photo varchar(30) );
and to upload and save an image file in MySQL DB I wrote the following code in addpic.php file:
---------------------------------------------------------
<?php
$con = mysql_connect (" "amirak17_test", "iud");
$db = mysql_select_db ("amirak17_test", $con);
error_reporting (E_ERROR);
$target = "/images/" . basename( $_FILES['photo']['name']);
$name = $_POST ['name'];
$pic = ($_FILES['photo']['name']);
mysql_query ("INSERT INTO test_pic VALUES ('$name', '$pic')");
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded.";
else
echo "Sorry, there was a problem uploading your file.";
?>
<form enctype="multipart/form-data" action="addpic.php" method="POST">
Name: <input type="text" name = "name"> <br />
Photo: <input type="file" name = "photo"> <br />
<input type="submit" value="Add">
</form>
---------------------------------------------------------
---------------------------------------------------------
To view the contents of the db I used the following code, in viewpic.php file, which only shows the name field not the pic :
---------------------------------------------------------
<?php
$con = mysql_connect (" "amirak17_test", "iud");
$db = mysql_select_db ("amirak17_test", $con);
$data = mysql_query("SELECT * FROM test_pic") or die(mysql_error());
while($info = mysql_fetch_array( $data ))
{
echo "<img src=['photo'] ."> <br>";
echo "Name: ".$info['name'] . "<br>";
}
?>
---------------------------------------------------------
---------------------------------------------------------
What am I missing, which is not uploading the file. The code works fine on a local computer.
Your help is highly appreciated.
CREATE TABLE test_pic
( name varchar (30), photo varchar(30) );
and to upload and save an image file in MySQL DB I wrote the following code in addpic.php file:
---------------------------------------------------------
<?php
$con = mysql_connect (" "amirak17_test", "iud");
$db = mysql_select_db ("amirak17_test", $con);
error_reporting (E_ERROR);
$target = "/images/" . basename( $_FILES['photo']['name']);
$name = $_POST ['name'];
$pic = ($_FILES['photo']['name']);
mysql_query ("INSERT INTO test_pic VALUES ('$name', '$pic')");
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded.";
else
echo "Sorry, there was a problem uploading your file.";
?>
<form enctype="multipart/form-data" action="addpic.php" method="POST">
Name: <input type="text" name = "name"> <br />
Photo: <input type="file" name = "photo"> <br />
<input type="submit" value="Add">
</form>
---------------------------------------------------------
---------------------------------------------------------
To view the contents of the db I used the following code, in viewpic.php file, which only shows the name field not the pic :
---------------------------------------------------------
<?php
$con = mysql_connect (" "amirak17_test", "iud");
$db = mysql_select_db ("amirak17_test", $con);
$data = mysql_query("SELECT * FROM test_pic") or die(mysql_error());
while($info = mysql_fetch_array( $data ))
{
echo "<img src=['photo'] ."> <br>";
echo "Name: ".$info['name'] . "<br>";
}
?>
---------------------------------------------------------
---------------------------------------------------------
What am I missing, which is not uploading the file. The code works fine on a local computer.
Your help is highly appreciated.