我从AIR桌面应用程序发送一个图像以及一些文本作为Base64编码的字符串。 如果图像大小约为100 KB,则上传可以正常工作,但如果图像大小大约为220 KB,我会在一段时间后重新收到错误。
该错误告诉 http://www.example.com/upload.php - 错误打开网址 ,但网址路径正确且可以找到。
我的PHP出了什么问题?
<?php
$file = $_POST["thefile"];
$text_message = $_POST["themessage"];
$subject = $_POST["thesubject"];
$from = $_POST["thesender"];
$to = $_POST["theaddress"];
$attachment=uniqid(rand(), true) . '.png';
$headers="From: $from\r\n";
$headers.="Reply-to: $from\r\n";
$headers.="Return-Path: $from\r\n";
if (isset($_ENV["SERVER_NAME"]))
$headers.="Message-Id: <" . md5(uniqid(microtime())) . "@" . $_ENV["SERVER_NAME"] . ">\r\n";
else
$headers.="Message-Id: <" . md5(uniqid(microtime())) . "@" . 'unknown' . ">\r\n";
$headers.="Date: " . date("r") . "\r\n";
$headers.="X-Mailer: PHP\r\n";
if (isset($_ENV["REMOTE_ADDR"]))
$headers.="X-SenderIP: " . $_ENV["REMOTE_ADDR"] . "\r\n";
else
$headers.="X-SenderIP: " . 'unknown' . "\r\n";
if (isset($_ENV["SERVER_NAME"]))
$headers.="X-WebSite: " . $_ENV["SERVER_NAME"] . "\r\n";
else
$headers.="X-WebSite: " . 'unknown' . "\r\n";
$headers.="X-Script: SWF_Generator\r\n";
$bound_text=md5(uniqid(time()));
$headers.="MIME-Version: 1.0\r\n" . "Content-Type: multipart/mixed; boundary=\"PHP-mixed-$bound_text\"\r\n";
$message="--PHP-mixed-$bound_text\r\n"
."Content-Type: text/html; charset=\"utf-8\"\r\n"
."Content-Transfer-Encoding: 7bit\r\n\r\n"
."<html><head></head><body>"
."<div style=\"font-family: Arial, Helvetica, sans-serif; font-size : 1.3em; color: #000000;width: 100%;text-align: left;\">$text_message</div></body></html>\r\n\r\n"
."--PHP-mixed-$bound_text\r\n"
."Content-Transfer-Encoding: base64\r\n"
."Content-Disposition: attachment; filename=\"$attachment\"\r\n"
."Content-Type: image/png; name=\"$attachment\"\r\n\r\n"
.chunk_split($file)
."\r\n\r\n"
."--PHP-mixed-$bound_text--\r\n\r\n";
mail($to,$subject,$message,$headers);
}
?>
服务器信息:
PHP Version 5.2.12-nmm2 System Debug Build: no Thread Safety: disabled Zend Memory Manager: enabled Registered PHP Streams: https, ftps, compress.zlib, compress.bzip2, php, file, data, http, ftp, zip Registered Stream Socket Transports: tcp, udp, unix, udg, ssl, sslv3, sslv2, tls Registered Stream Filters: zlib.*, bzip2.*, convert.iconv.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed
答案 0 :(得分:1)
从phpinfo()中查看upload_max_filesize和post_max_size。它们通常以兆字节为单位,但无论如何都要检查。 post_max_size应该是上传的最大文件大小的两倍。
检查服务器日志以查找php错误。
答案 1 :(得分:0)
也许你应该使用amfphp或发送post数据方法? 使用Base64的方式确实较慢,需要服务器处理,你可以避免它。
链接到post方法: http://www.neerfri.com/2007/12/flex-multipartform-data-post-request.html