PDA

View Full Version : Error in image file upload using dreamweaver


mnwuzor
02-16-2014, 11:34 PM
Greeting to you all!

Please I need you PRO help. My case seem similar to some of the ones I have seen but my code is completely different.

I wrote this code below using PHP in Dreamweaver and its used to upload images to MySQl database. Now when I upload about 6 images, it shows File Uploaded Successfully. But if I try to upload any thing below 6 images, it will refuse to upload and will echo Upload Failed.

<?php
if(isset($_POST['submit']))
{
$projid=$_POST['projid'];
$projname=$_POST['projname'];

$name=basename($_FILES['file_upload']['name']);
$t_name=$_FILES['file_upload']['tmp_name'];
$dir='upload';
if(move_uploaded_file($t_name,$dir."/".$name))

$nameone=basename($_FILES['file_uploadone']['name']);
$t_name=$_FILES['file_uploadone']['tmp_name'];
$dir='upload1';
if(move_uploaded_file($t_name,$dir."/".$name))

$nametwo=basename($_FILES['file_uploadtwo']['name']);
$t_name=$_FILES['file_uploadtwo']['tmp_name'];
$dir='upload2';

if(move_uploaded_file($t_name,$dir."/".$name))
$namethree=basename($_FILES['file_uploadthree']['name']);
$t_name=$_FILES['file_uploadthree']['tmp_name'];
$dir='upload3';

if(move_uploaded_file($t_name,$dir."/".$name))
$namefour=basename($_FILES['file_uploadfour']['name']);
$t_name=$_FILES['file_uploadfour']['tmp_name'];
$dir='upload4';
if(move_uploaded_file($t_name,$dir."/".$name))

$namefive=basename($_FILES['file_uploadfive']['name']);
$t_name=$_FILES['file_uploadfive']['tmp_name'];
$dir='upload5';
if(move_uploaded_file($t_name,$dir."/".$name))
{
mysql_select_db ($database_ProjMonEva,$ProjMonEva);
$qur="insert into tbl_images (imageid, projid, projname, name, path, nameone, pathone, nametwo, pathtwo, namethree, paththree, namefour, pathfour, namefive, pathfive) values ('','$projid','$projname','$name','upload/$name','$nameone','upload/$ nameone','$nametwo','upload/$nametwo','$namethree','upload/$namethree' ,'$namefour','upload/$namefour','$namefive','upload/$namefive')";
$res=mysql_query($qur,$ProjMonEva);
echo 'File uploaded successful';
}
else
{
echo 'upload failed!';
}
}
?>

I see the problem to come from the echo but I am stock and dont know how to correct it. Can any one please help me.

Thank you in advance Mike

edbr
02-17-2014, 01:27 AM
without getting to deeply into your code , as I dont have a lot of spare time at the moment, you should look at putting the file uploads into an if condition
if(!empty($_POST['upload2'];)) {

do stuff
}