根据下面的代码安全地将图像上传到php脚本的最佳做法是什么?我使用文件传输cordova插件将图像上传到php脚本。
Javascript(文件传输cordova插件)
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
options.mimeType = "image/jpeg";
var params = new Object();
params.imageLink = "test";
options.params = params;
options.chunkedMode = false;
var ft = new FileTransfer();
ft.upload(imageURI, "http://example.com/upload.php", win, fail, options);
alert("Post Uploading");
function win(r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
alert(r.response);
}
function fail(error) {
$.mobile.loading('hide');
navigator.notification.alert("An error has occurred: Code = " + error.code, null, 'Alert', 'OK');
}
PHP
<?php
if(isset($_POST['imageLink'])) {
$imageLink = $_POST['imageLink'];
print_r($_FILES);
$new_image_name = $imageLink.".jpg";
move_uploaded_file($_FILES["file"]["tmp_name"], “uploads/“.$new_image_name);
}
?>
有什么建议吗?
答案 0 :(得分:0)
取决于要保护的内容:
上面的列表只是一个开始。安全是一个比我们预期更深的兔子洞。