I have this script that allows you to upload an image, and then the pointer is stored in the database in a file on the file system. I got this script from another StackOverflow question, and it does almost everything I need, except for two things. The first thing I need is to resize the images, and the second part that I just read about is to rename the file to prevent user errors, etc.
Here is a download file that takes form data from the user input form and writes the data to the database and image in the image catalog.
<?php
$target = "your directory";
$target = $target . basename( $_FILES['photo']['name']);
$name=$_POST['nameMember'];
$bandMember=$_POST['bandMember'];
$pic=($_FILES['photo']['name']);
$about=$_POST['aboutMember'];
$bands=$_POST['otherBands'];
mysql_connect("yourhost", "username", "password") or die(mysql_error()) ;
mysql_select_db("dbName") or die(mysql_error()) ;
mysql_query("INSERT INTO tableName (nameMember,bandMember,photo,aboutMember,otherBands)
VALUES ('$name', '$bandMember', '$pic', '$about', '$bands')") ;
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
?>
source
share