The code below is what i am using to upload a photo to store it in a database, is it being stored correctly?? as it will not let me view them properly, any help is great!!!
$title = $_POST["title"];
$userfile = $_FILES['userfile']['tmp_name'];
$userfile_name = $_FILES['userfile']['name'];
$userfile_size = $_FILES['userfile']['size'];
$userfile_type = $_FILES['userfile']['type'];
$userfile_error = $_FILES['userfile']['error'];
if ($userfile=='none')
{
echo 'You have not attempted to upload a file!!';
?>
<a href="uploadphoto.php"><br />Please try again...</a>
<?php
exit;
}
if ($userfile_size==0)
{
echo 'The file you are trying to upload has 0 length!!';
?>
<a href="uploadphoto.php"><br />Please try again...</a>
<?php
exit;
}
if (strpos($userfile_type , 'image/') !== 0)
{
echo 'The file you are trying to upload is not an image!!';
?>
<a href="uploadphoto.php"><br />Please try again...</a>
<?php
exit;
}
if($userfile_error > 0)
{
echo 'A prolem has occured whilst trying to upload the photo!!';
?>
<a href="uploadphoto.php"><br />Please try again...</a>
<?php
exit;
}
$PSize = filesize($userfile);
$mysqluserfile = addslashes(fread(fopen($userfile, "r"), $PSize));
$upfile = 'C:/wamp/www/Playhill/images/'.$userfile_name;
if (is_uploaded_file($userfile))
{
if(!copy($userfile, $upfile))
{
echo 'Sorry the file could not be moved!!';
?>
<a href="uploadphoto.php"><br />Please try again...</a>
<?php
exit;
}
mysql_query("INSERT INTO photos (title, name) VALUES ('$title','$mysqluserfile')");
} else {
echo"You did not upload any picture";
?>
<a href="uploadphoto.php"><br />Please try again...</a>
<?php
}
echo '<br />Your image below has been uploaded succesfully!<br /> <br />';