Im пытается настроить Mosync Фото галерея образец, который вы можете найти here и here.Android Html5/java app: галерея mosync загрузить и отправить по электронной почте
Это/Java приложение которым Html взять snaphot, а затем загрузить сфотографировались на веб-сервер через файл PHP (в этом случае файл upload.php)
Everythings отлично работает для меня, но я хотел бы добавить поле электронной почты и попросить пользователя ввести его адрес электронной почты в это поле перед загрузкой. Я хотел бы отправить это письмо с прикрепленным изображением, но хочу сделать это на стороне сервера (php) после завершения загрузки.
Я попытался добавить в файл upload.php почтовую функцию (с заранее определенным адресом отправителя и ссылкой на картинку), и она работает, но я не могу получить сообщение о возврате на устройстве, сообщающее пользователь, который загружает завершен. Это является излишним, поскольку пользователь не знает, если процесс завершен.
Я блокирую на разных этапах: 1: Как восстановить адрес электронной почты, введенный пользователем и передающий его для загрузки .php 2: Как добавить загруженное изображение в качестве прикрепления и отправить его пользователю 3: Как сохранить сообщение о состоянии на устройстве?
Есть ли у кого-нибудь такие же вопросы? Есть ли у кого-нибудь опыт работы с этим примером Mosync App?
Спасибо за любую помощь
Ниже файла 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='<[email protected]>';
$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();
}
?>
Mikael, Спасибо, что нашли время, чтобы ответить. Я пробовал то, что вы предлагаете, но у меня все еще есть проблема с функцией электронной почты. Я не могу получить адрес электронной почты пользователя в файле upload.php. Я получаю [объект HTMLInputElement] вместо значения электронной почты. поле ввода в pagecamera.html выглядит следующим образом: . Должен ли я устанавливать форму для поля ввода? Есть идеи ? Спасибо –
Немного для этого! У меня есть устранение неполадок, и я считаю, что значение поля электронной почты в pagecamera.html не передается index.html, поэтому я не могу получить его на стороне сервера. Есть идеи? –