I have now followed the tutorials as you suggested and although i understand the principle of it all, I still cant get the damn thing to work.
I copied the source code and changedthe directory path as instructed and set up the config file with my database name etc and when i hit submit on the form i get this following error
Warning: move_uploaded_file(/home/public_html/upload/pictures/earth.gif): failed to open stream: No such file or directory in /home/sites/grap.co.uk/public_html/upload/upload3.php on line 36
Warning: move_uploaded_file(): Unable to move '/tmp/phpLCghqb' to '/home/public_html/upload/pictures/earth.gif' in /home/sites/grap.co.uk/public_html/upload/upload3.php on line 36
Error uploading file
the file i saved has the code as follows:
<html>
<head>
<title>Upload File To MySQL Database</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.box {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
border: 1px solid #000000;
}
-->
</style>
</head>
<body>
<?
// you can change this to any directory you want
// as long as php can write to it
$uploadDir = '/home/public_html/upload/pictures/';
if(isset($POST['upload']))
{
$fileName = $FILES['userfile']['name'];
$tmpName = $FILES['userfile']['tmp_name'];
$fileSize = $FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
// the files will be saved in filePath
$filePath = $uploadDir . $fileName;
// move the files to the specified directory
// if the upload directory is not writable or
// something else went wrong $result will be false
$result = move_uploaded_file($tmpName, $filePath);
if (!$result) {
echo "Error uploading file";
exit;
}
include 'library/config.php';
include 'library/opendb.php';
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$filePath = addslashes($filePath);
}
$query = "INSERT INTO upload2 (name, size, type, path ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$filePath')";
mysql_query($query) or die('Error, query failed : ' . mysql_error());
include 'library/closedb.php';
echo "<br>File uploaded<br>";
}
?>
<form action="" method="post" enctype="multipart/form-data" name="uploadform">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr>
<td width="246"><input type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="userfile" type="file" class="box" id="userfile">
</td>
<td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
</tr>
</table>
</form>
</body>
</html>
I have changed the CHMOD to 777 for my pictures directory .
I am obviously missing something obvious or i have put the path to my save drectory incorrectly.
Someone please put me out of my misery
🙂