Question

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!';
}
}
?>
<?php

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

Was it helpful?

Solution 2

I have been able to resolve the issue. You can view the code update here http://forums.adobe.com/message/6132524#6132524

Check the last post on the page.

Thank you for your help.

Prince Mike

OTHER TIPS

You are putting a condition if(move_uploaded_file($t_name,$dir."/".$name)) but then you are not indicating what happens if the condition is met so only the first line (just after the if) is taken as what to do if the condition is met.

In fact you are only doing it once correctly using {}:

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';    
}

The best thing you can do is to create a function and for each loaded file call the function.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top