Hello..
Im trying to create an upload script which will upload a file into a directory and add the 'file name' into a database called 'gallery'.
I have got the upload part working, it uploads an image for example into my specified folder, but the adding to database part I cant get working. I must be doing something stupid.
I tryed to add the $userfile to the database, as thats the name of my file import in the form, but that didnt add anything to the database at all.
Ideally im after the name of the image, so if i was to upload 'mofish.jpg' it would add 'mofish.jpg' to the database.
I cant see where im going wrong, or even if im on the right path. Here is my code anyways, so far. Needs more validation and stuff I know, its basic for now.
Thanks, Mofish
Im trying to create an upload script which will upload a file into a directory and add the 'file name' into a database called 'gallery'.
I have got the upload part working, it uploads an image for example into my specified folder, but the adding to database part I cant get working. I must be doing something stupid.
I tryed to add the $userfile to the database, as thats the name of my file import in the form, but that didnt add anything to the database at all.
Ideally im after the name of the image, so if i was to upload 'mofish.jpg' it would add 'mofish.jpg' to the database.
I cant see where im going wrong, or even if im on the right path. Here is my code anyways, so far. Needs more validation and stuff I know, its basic for now.
Thanks, Mofish
Code:
<?php
//theres a warning and i cant get rid of it, this prevents it. :)
error_reporting(0);
$userfile = $_POST['userfile'];
$member = $_SESSION['member'];
$query = "insert into `gallery` (`image`, `author`) values ($userfile', '$member')";
$uploaddir = '/home/mo/public_html/php-development/UNISite/pages/upload/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
echo "<div>Welcome - You Have A <b>5MB</b> Upload Limit</div>";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
if (mysql_query($query)){
echo "Successfully added to database.\n";
} else {
echo "not added to database.\n";
}
echo "Successfully uploaded.\n";
} else {
echo "An Error Occoured, Please Try Again\n";
}
?>
<form enctype="multipart/form-data" action="index.php?page=upload" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="5242880" />
Send this file: <input name="userfile" type="file" class="loginbox" />
<input type="submit" value="Send File" class="loginbox" />
</form>
Last edited: