Image upload problem
Posted: Sat Jun 07, 2008 1:01 pm
Got my code from some tutorial online, it was written so it confirms the file type but the file type in the tutorial was for MS Office Documents, I've adapted the code to upload images, but here is a problem it will eather upload any file, when i put a few different image types or no files at all if i put only one file type, anyway here is the code, version that will upload anything
Code: Select all
<?php
if(isset($_POST['submit'])){
$numfilesuploaded = $_POST['numuploads'];
$count = 1;
while ($count <= $numfilesuploaded)
{
$conname = "new_file".$count;
$filetype = $_FILES[$conname]['type'];
$filename = $_FILES[$conname]['name'];
if ($filename != '')
{
if ($filetype == "image/JPEG" || "image/jpeg" || "image/JPG" || "image/jpg")
{
$maxfilesize = $_POST['maxsize'];
$filesize = $_FILES[$conname]['size'];
if($filesize <= $maxfilesize )
{
$randomdigit = rand(0000,9999);
$newfilename = $randomdigit.$filename;
$source = $_FILES[$conname]['tmp_name'];
$target = "adpics/".$newfilename;
move_uploaded_file($source, $target);
$key = $_GET['key'];
require_once('conf.php');
$connection = mysql_connect($host, $user, $pass) or die ('Unable to connect!');
mysql_select_db($db) or die ('Unable to select database!');
$query = mysql_query("INSERT INTO padpics (`rkey`, `file`) VALUES ('$key', '$newfilename')");
header("Location: ../register1.php");
}
else
{
echo $count." File is too big! 10MB limit! |";
}
}
else
{
echo " The file is not a supported type |";
}
}
$count = $count + 1;
}
}
?>
<html>
<?php
$numuploads = 10;
$count = 1;
?>