Im trying to upload an image to my server and then copy information to a MySQL database.
this is my code that isnt working.
<html>
<head>
<title>Uploading...</title>
</head>
<body>
<h1>Uploading file...</h1>
<?php
include_once("./include/config.php");
db_connect();
if ($_FILES['userfile']['error'] > 0)
{
echo 'Problem: ';
switch ($_FILES['userfile']['error'])
{
case 1: echo 'File exceeded upload_max_file_size'; break;
case 2: echo 'File exceeded max_file_size'; break;
case 3: echo 'File only partially uploaded'; break;
case 4: echo 'No File Uploaded'; break;
}
exit;
}
// Does the file have the right MIME type?
//Put the file where we'd like it
$upfile = './images/'.time().$_FILES['userfile']['name'] ;
$tmpfile = $_FILES['userfile']['tmp_name'] ;
$imgloc = $_POST['imglocation'];
echo $upfile;
echo '<br /><b>';
echo $imgloc;
echo '</b><br />';
if (is_uploaded_file($tmpfile))
{
if (!move_uploaded_file($tmpfile, $upfile))
{
echo 'Could not move file to destination';
exit;
}
}
else
{
echo 'Possible File Upload Attack. Filename: ';
echo $_FILES['userfile']['name'];
exit;
}
$date = date("Y-m-d");
$sqlresult = mysql_query ("INSERT INTO `photos` (photo_title, photo_desc, photo_date, photo_location) VALUES ('$upfile', '1', '$date', '$imgloc'");
if (!$sqlresult){
die('<br />Invalid Query: ' . mysql_error());
};
echo '<div align="center">';
echo 'File uploaded successfully<br /><br />';
echo '<b>Preview: </b><br />';
echo '<img border="2" src="'.$upfile.'" width="30%" >';
echo '</div>';
?>
</body>
</html>
can n e 1 help plz ?