簡體   English   中英

無法存儲上載的圖像文件

[英]Having trouble storing uploaded image file

我有兩個文件,我希望用戶上傳。 表單看起來像這樣。

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

將信息發送到的PHP文件是這樣的:

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

但是,我不斷收到“ 0”的回聲。 這意味着該代碼無法通過太大的測試,即使我知道它實際上不是太大的文件也是如此。 此外,文件也不會移動到新文件位置。

這里看起來有什么問題? 謝謝。

if(isset($_POST['FrontDesign']))更改為if(isset($_FILES['FrontDesign']))因為它不是文本輸入,而是文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM