我正在尝试自定义您可以在 此处和此处找到的 Mosync 照片库示例。
这是一个 Html/java 应用程序,它可以拍摄快照,然后通过 php 文件将拍摄的照片上传到 Web 服务器(在本例中,文件是 upload.php)
一切对我来说都很好,但我想添加一个电子邮件字段并要求用户在上传之前在此字段中输入他的电子邮件地址。我想发送这封附有图片的电子邮件,但想在上传完成后在服务器端 (php) 执行此操作。
我试图在upload.php文件中添加一个邮件功能(带有预定义的发送地址和图片链接),它可以工作,但是我无法在设备上获得返回状态消息,告诉用户上传是完成。这很烦人,因为用户不知道过程是否完成
我阻止了不同的步骤: 1:如何恢复用户输入的电子邮件地址并将其传递给 upload.php 2:如何将上传的图片添加为附件并将其发送给用户 3:如何保持状态设备上显示的消息?
这里有没有人遇到过同样的问题?有人对这个示例 Mosync 应用程序有经验吗?
谢谢你的帮助
下面使用的upload.php文件:
<?php
ini_set("display_errors", "1");
ini_set("log_errors", "1");
error_reporting(-1);
function mylog($message)
{
$file = 'mylog.txt';
// Open the file to get existing content
$current = file_get_contents($file);
// Append a line to the file
$current .= "$message\n";
// Write the contents back to the file
file_put_contents($file, $current);
}
function uploadPhoto()
{
$targetPath = "test/" . basename($_FILES["file"]["name"]);
if (fileIsOK($_FILES["file"]))
{
$success = move_uploaded_file($_FILES["file"]["tmp_name"], $targetPath);
if ($success)
{
echo "The file " . basename($_FILES["file"]["name"]) .
" has been uploaded";
}
else
{
echo "There was an error uploading the file";
}
}
else
{
echo "Not a valid image file";
}
}
function fileIsOK($file)
{
return $file["size"] < 1500000
&& fileIsImage($file["name"]);
}
function fileIsImage($path)
{
return endsWith($path, ".jpeg")
|| endsWith($path, ".jpg")
|| endsWith($path, ".png");
}
function endsWith($haystack, $needle)
{
$expectedPosition = strlen($haystack) - strlen($needle);
return strripos($haystack, $needle, 0) === $expectedPosition;
}
function getPhotoURLs()
{
/*// For debugging.
$urls = getLastTenPhotoURLs();
foreach ($urls as $url)
{
echo "<a href='$url'>$url</a><br/>\n";
}*/
echo getPhotoURLsAsJSON();
}
function getPhotoURLsAsJSON()
{
$urls = getLastTenPhotoURLs();
return json_encode($urls);
}
// Gets last TEN photo urls.
function getLastTenPhotoURLs()
{
$baseURL = "http:THE URL WHERE PHOTOS WILL BE POSTED";
$baseDir = "test/";
$files = array();
// Add files to table using last mod time as key.
if ($handle = opendir($baseDir))
{
while (false !== ($file = readdir($handle)))
{
if ("." != $file && ".." != $file)
{
$files[filemtime($baseDir . $file)] = $file;
}
}
closedir($handle);
}
// Sort by mod time.
ksort($files);
// Last ones first.
$files = array_reverse($files);
// List if URLs.
$urls = array();
// Create a list of URLs to the most recent files.
$fileCounter = 0;
foreach ($files as $file)
{
++$fileCounter;
// We only get TEN recent files (100 is too many!).
if ($fileCounter > 10)
{
// TODO: Move excessive files to an archive directory?
break;
}
array_push($urls, $baseURL . $file);
}
return $urls;
}
function sendHTMLemail($HTML,$from,$to,$subject)
{
$url="http:THE URL OF THE POSTED PHOTOS;
$mailto .= 'THE EMAIL OF THE USER';
$HTML="
<table style='font-size:13px' width='700' border='0' cellspacing='0' cellpadding='3'>
<tr>
<td colspan='2'>Dear friend,<br></td>
</tr>
<tr>
<td colspan='2' bgcolor='#ffffff'>Attached, you will find the picture taken during our last event.</strong></td>
</tr>
<tr>
<td colspan='2' bgcolor='#ffffff' width='250' >link to the <a href=".$url.">gallery</a></td>
</tr>
</table>";
$from='<noreply@noreply.be>';
$subject='Picture';
$to= $mailto;
$headers = "From: $from\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= //"--$boundary\r\n".
"Content-Type: text/html; charset=ISO-8859-1\r\n";
//"Content-Transfer-Encoding: base64\r\n\r\n";
mail($to,$subject,$HTML,$headers);
}
// If file data is posted then upload the file,
// else get the list of image urls.
if (isset($_FILES["file"]))
{
sendHTMLemail($HTML,$from,$to,$subject);
uploadPhoto();
}
else
{
getPhotoURLs();
}
?>