【发布时间】:2011-11-20 08:59:22
【问题描述】:
我正在开发一个 Web 应用程序,它使用 JQuery AJAX 和 PHP 将一些数据上传到我的数据库中。
要提交的表单的其中一个字段是图像的 URL(WEB 的任何地址)。此图像应下载到我的 FTP 服务器,然后将其新地址插入数据库。
如何从任何 URL 下载图像并将其上传到我的 FTP 服务器?
表格:
<form id="form-id" method="post" action="insert.php" charset=utf-8">
<input type="text" name="title" id="title">
<input type="text" name="image-url" id="image-url">
<input type="submit" name="submit" id="submit">
</form>
JavaScript
$("#submit").live("click", function(event){
event.preventDefault();
$.ajax({
type : "POST",
url : "insert.php",
data : {
'title': valueTitle,
'image': valueImage
},
cache : false,
success : function(html) {
if (html == "success") {
//...
} else if (html == "ftp-error") {
//...
} else if (html == "sql-error") {
//...
}
}
});
});
插入.php
$title = $_REQUEST['title'];
$image = $_REQUEST['image'];
$imageInMyServer = downloadImageFromURLAndUploadFTP($image);
function downloadImageFromURLAndUploadFTP($image) {
//that is what I want to know how to do.
}
//sql query with $title and $imageInMyServer
注意事项:
- 我要下载的文件不在我的服务器上。它位于 Internet 的其他位置,我需要将其下载到我的 FTP 服务器
- 没有。我无法在我的 SQL 查询中使用第一个外部 URL
【问题讨论】:
标签: php ajax jquery ftp download