gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 00:40:22 24 4
gpt4 key购买 nike

向大家问好!

拜托,我需要你的专业帮助。我的案例看起来与我见过的一些案例相似,但我的代码完全不同。

我在 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

我发现问题来自 echo ,但我有库存,不知道如何纠正它。任何人都可以帮助我吗?

提前谢谢您迈克

最佳答案

您正在设置一个条件 if(move_uploaded_file($t_name,$dir."/".$name)) 但您没有指示如果满足条件会发生什么,因此只有第一个行(就在 if 之后)被视为满足条件时要执行的操作。

事实上,您仅使用 {} 正确执行一次:

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

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

关于php - 使用 Dreamweaver 上传图像文件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21818143/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com