我不是一个大 Jquery 人,但我正在使用一个插件,它是一个图像上传器。它有一个按钮来删除与以下代码相关的图像。
function remove_unwanted_file(id,file)
{
if(confirm("If you are sure that you really want to remove the file "+file+" then click on OK otherwise, Cancel it."))
{
var dataString = "file_to_remove=" +file;
$.ajax({
type: "POST",
url: "remove_unwanted_files.php",
data: dataString,
cache: false,
beforeSend: function()
{
$("#vpb_remove_button"+id).html('<img src="images/loadings.gif" align="absmiddle" />');
},
success: function(response)
{
$('div#fileID'+id).fadeOut('slow');
}
});
}
return false;
}
但是,PHP 文件中的任何代码都不会被执行。确实会弹出警报并询问您是否要删除具有正确文件名的文件。PHP 代码是实际删除文件的内容,但文件不会从文件系统中删除。我尝试将其他代码放入 PHP 文件中,例如向我发送电子邮件,但没有一个执行。任何人都可以看到这个 JQuery 代码有什么问题吗?
这是 PHP 代码
<?php
$to = 'dev@kylevan.com';
$subject = 'the subject';
$message = 'file reached';
$headers = 'From: noreply@mobilehomelist.com' . "\r\n" .
'Reply-To: noreply@mobilehomelist.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
include('ASApiClientServer.php');
include('ASApiClient.php');
$uniquekey=$_SESSION['uniquekey'];
$postFields = array(
'referralCode'=>$uniquekey,
'image'=>strip_tags($_POST["file_to_remove"]),
),
);
$ApiClient = new ASApiClient();
try{
$ApiClient->requestResponse('removePicture', $postFields);
//handle the call
}
catch(Exception $e){
print_r($ApiClient->getRawResponse());
}
if(isset($_POST["file_to_remove"]) && !empty($_POST["file_to_remove"]))
{
$uploaded_files_location = 'uploaded_files/'.strip_tags($_POST["file_to_remove"]);
@chmod($uploaded_files_location,0777);
@unlink($uploaded_files_location);
//Here you can also delete the file from your database if you wish assuming you also saved the file to your database during upload
}
?>
一开始的电子邮件内容只是试图让它做某事。文件的路径是正确的。