I am a novice with php and html. I have been working with the code in the "PHP, MySQL and images" article. I have gotten everything working except for the image upload. here is what I now have...
<form enctype="multipart/form-data" method="post" action="<?php echo $PHP_SELF ?>">
Denotes a required field<br><br>
Link Address <br> <input type="Text" name="address" size="70" maxlength="70" value="http://"><br>
Site/Link Name *<br> <input type="Text" name="name" size="30" maxlength="30"><br>
Link Image<br><input type="file" name="image" size="30" maxlength="30">
<br><br><input type="submit" name="submit" value="Upload">
<input type="reset" name="reset" value="Reset The Form">
</form>
<?php
$database="myDatabase";
$hostname="localhost";
$username="myUsername";
$password="myPassword";
if ($submit) {
$db = mysql_connect("$hostname","$username","$password")
or die ("Couldn't connect to server.");
mysql_select_db("$database",$db)
or die ("Couldn't connect to DataBase.");
mysql_query("INSERT INTO HyperLinks (address, name, image)
VALUES ('$address', '$name', '$image')
");
exec("cp $image image/$image_name");
echo "address: $address<br>\n";
echo "name: $name<br>\n";
echo "temp file: $image<br>\n";
echo "file name: $image_name<br>\n";
echo "file size: $image_size<br>\n";
echo "file type: $image_type<br>\n";
echo "<br>\n";
echo "<img src=/image/$image_name><br>\n";
}
?>
I placed an "or die" after [[ exec("cp $image image/$image_name"); ]] and found out that this line was failing. I noticed that the line [[ echo "temp file: $image<br>\n"; ]] would output " temp file: /tmp/phpsomerandomnumber ". I am wondering if this mystery /tmp/ directory is where my files are going.. I can't find them on my client or server drive??? The line [[ echo "<img src=/image/$image_name><br>\n"; ]] just displays the broken image icon. I checked some of the discussions here and the w3c.org site and found limited info on the encdata setting and the input tag. I'm just not sure where to look next. BTW my hosting companies server runs RH Linux so I believe the syntax of the copy command is correct. Any help would be greatly appreciated. Thank you in advance for your assistance.