使用Dreamweaver上传图像文件时出错

时间:2014-02-16 23:17:24

标签: php mysql dreamweaver

向大家致意!

我需要你的PRO帮助。我的情况看起来与我见过的一些相似,但我的代码完全不同。

我在Dreamweaver中使用PHP编写了以下代码,用于将图像上传到MySQl数据库。现在,当我上传大约6张图片时,会显示文件已成功上传。但是,如果我尝试上传6张图片以下的任何内容,它将拒绝上传,并会回显上传失败

<?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

我看到问题来自回声,但我是股票,不知道如何纠正它。任何人都可以帮助我。

提前谢谢你 麦克

2 个答案:

答案 0 :(得分:0)

你正在设置一个条件if(move_uploaded_file($t_name,$dir."/".$name)),但是你没有说明如果满足条件会发生什么,所以只有第一行(就在if之后)被视为满足条件时要做的事情。< / p>

事实上,您只能使用{}正确执行此操作:

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

您可以做的最好的事情是创建一个函数,并为每个加载的文件调用该函数。

答案 1 :(得分:0)

我已经能够解决这个问题。您可以在此处查看代码更新http://forums.adobe.com/message/6132524#6132524

检查页面上的最后一篇文章。

感谢您的帮助。

迈克王子