I'm sending from a AIR desktop application an image along with some text as a Base64 encoded string. If the image size is around 100 KB the upload works but if its a bigger one ~220 KB I get an Error thrown back after some time.
The error tells http://www.example.com/upload.php - Error opening URL but the url path is correct and can be found.
What is wrong with my 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);
}
?>
Server informations:
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
check out upload_max_filesize and post_max_size from phpinfo(). They usually are in megabytes but check anyway. post_max_size should be twice the size of the largest file uploaded.
Check out server logs for the php error.
Maybe you should use amfphp or send post data method ? Your way with Base64 is for sure slower and require server processing , You can avoid it.
link to post method : http://www.neerfri.com/2007/12/flex-multipartform-data-post-request.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.