douchendan0040 2015-01-22 00:13
浏览 43
已采纳

存储上传的图像文件时出错

I have two files I would like the user to upload. Form looks like this.

<form action="send-image.php" method="POST" enctype="multipart/form-data">
  Upload image 1
        <input type="file" name="FrontDesign">
  Upload image 2
        <input type="file" name="BackDesign">
        <input type="submit" value="Submit images" >
</form>

The PHP file it sends the info to is like this:

require 'includes/PHPMailer/PHPMailerAutoload.php';

$frontdesign = $_FILES['FrontDesign'];
$backdesign = $_FILES['BackDesign'];

$target_path = "";
$target_path2 = "";

if(isset($_POST['FrontDesign'])) {

if (($_FILES["FrontDesign"]["size"] < 1200000000000)){
    if($_FILES["FrontDesign"]["type"] == "image/jpeg"){$ptype=".jpeg";}
    elseif($_FILES["FrontDesign"]["type"] == "image/jpg"){$ptype=".jpg";}
    elseif($_FILES["FrontDesign"]["type"] == "image/pjpeg"){$ptype=".pjpeg";}
    elseif($_FILES["FrontDesign"]["type"] == "image/png"){$ptype=".png";}

    $target_path = "Images/";
    $randf = rand(1000, 9999).rand(1000, 9999).rand(1000, 9999).rand(1000, 9999).rand(1000, 9999);
    $target_path = $target_path . $randf . $ptype; 

    move_uploaded_file($_FILES['FrontDesign']['tmp_name'], $target_path);
    // wrong file type
    } else{echo  $error =1; }

} else { $target_path = 0; }

if(isset($_POST['BackDesign'])) {

    if (($_FILES["BackDesign"]["size"] < 1200000000000)){
        if($_FILES["BackDesign"]["type"] == "image/jpeg"){$ptype2=".jpeg";}
        elseif($_FILES["BackDesign"]["type"] == "image/jpg"){$ptype2=".jpg";}
        elseif($_FILES["BackDesign"]["type"] == "image/pjpeg"){$ptype2=".pjpeg";}
        elseif($_FILES["BackDesign"]["type"] == "image/png"){$ptype2=".png";}

        $target_path2 = "Images/";
        $randf2= rand(1000, 9999).rand(1000, 9999).rand(1000, 9999).rand(1000, 9999).rand(1000, 9999);
        $target_path2 = $target_path2 . $randf2 . $ptype2; 

        move_uploaded_file($_FILES['BackDesign']['tmp_name'], $target_path2);
        // wrong file type
        } else {echo $error =1; }

    } else { $target_path2 = 0; }       


echo "$target_path, $target_path2";

// PHPMailer
$mail = new PHPMailer();

$mail->addAddress('collegepregame@gmail.com');
$mail->SetFrom = "test@mail.com";
$mail->FromName = "Zach Cook";

$file_to_attach = $target_path;
$file_to_attach2 = $target_path2;

$mail->AddAttachment( $file_to_attach );
$mail->AddAttachment( $file_to_attach2 );
$mail->isHTML(true);

$mail->Subject = "Testing image send";
$mail->Body = "Does it work now?";

if(!$mail->send()) {
    echo 'Message could not be sent.';
}

However, I keep getting a "0" echoed out. Meaning that the code fails the test for being too big, even though I know it really isn't too large a file. Also, the file is not being moved to the new file location.

What looks to be wrong here? Thanks.

  • 写回答

1条回答 默认 最新

  • douli1306 2015-01-22 00:21
    关注

    change if(isset($_POST['FrontDesign'])) to if(isset($_FILES['FrontDesign'])) as it's not an input of text but file.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料