0
我有一個PHP窗體,我試圖從它發送一個圖像作爲附件。我已經在我的代碼中修復了幾件事。發送圖像附件
- 我不知道這是否會送形象(因爲我有一些問題吧)
- 的問題是,沒有在頁面甚至顯示(當我下面的腳本是RAN)時我打開它在服務器上爲
index.php
甚至沒有按鈕
下面是代碼:
<?php
include_once("functions.php");
// Process
$action = isset($_POST["action"]) ? $_POST["action"] : "";
if (empty($action))
{
// Send back the contact form HTML
$output = "<form action='#' style='display:none'>
<input type='file' id='image' name='image' maxlength=50>";
}
require("class.phpmailer.php");
$Email_to = "[email protected]"; // the one that recieves the email
$email_from = "[email protected]";
$dir = "uploads/$filename";
chmod("uploads",0777);
function uploadImage($image)
{
if ((($_FILES["image"]["type"] == "image/gif")
|| ($_FILES["image"]["type"] == "image/jpeg")
|| ($_FILES["image"]["type"] == "image/pjpeg")
|| ($_FILES["image"]["type"] == "image/jpg")
|| ($_FILES["image"]["type"] == "image/png"))
&& ($_FILES["image"]["size"] < 2097152)
&& (strlen($_FILES["image"]["name"]) < 51))
{
if ($_FILES["image"]["error"] > 0)
{
echo "Return Code: " . $_FILES["image"]["error"];
}
else
{
echo "Upload: " . $_FILES["image"]["name"] . "<br />";
echo "Type: " . $_FILES["image"]["type"] . "<br />";
echo "Size: " . ($_FILES["image"]["size"]/1024) . " Kb<br />";
echo "Temp file: " . $_FILES["image"]["tmp_name"] . "<br />";
if (file_exists("images/" . $_FILES["image"]["name"]))
{
echo $_FILES["image"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["image"]["tmp_name"],
"images/" . $_FILES["image"]["name"]);
}
}
}
else
{
echo "Invalid file";
}
$filename = $_FILES["image"]["type"];
$dir = "uploads/$filename";
chmod("uploads",0777);
$success = copy($_FILES[images][tmp_name], $dir);
if ($success)
{
echo " Files Uploaded Successfully<BR>";
SendIt();
}
}//end of upload func'
function SendIt() {
//
global $attachments,$Email_to,$Email_msg,$email_subject,$email_from;
$mail = new PHPMailer();
$mail->IsSMTP();// send via SMTP
$mail->Host = "localhost"; // SMTP servers
$mail->SMTPAuth = false; // turn on/off SMTP authentication
$mail->From = $email_from;
$mail->AddAddress($Email_to);
$mail->AddReplyTo($email_from);
$mail->WordWrap = 50;// set word wrap
//now Attach all files submitted
$mail->AddAttachment("uploads"."/".$_FILES["image"]["type"]);
$mail->IsHTML(false);// send as HTML
}
?>
預先感謝您!
我加了這三行: – shmnsw
我加了這三行:echo $ output; // $ image = $ _POST [「image」]; uploadImage($ image);緊接在:if(empty($ action))塊之後,仍然沒有顯示任何內容。 – shmnsw