我不是一个大家伙Jquery的,但现在用一个插件,它是一个图片上传。它有一个按钮,用于删除与以下代码相关的图像。jQuery函数不张贴到PHP
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 = '[email protected]';
$subject = 'the subject';
$message = 'file reached';
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\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
}
?>
开头的电子邮件的东西在里面只是想获得它做什么。该文件的路径是正确的。
在同一个目录中的文件?控制台上的任何错误? – Sergio
你确定它是一个发布请求吗? – KyleK
确保参数'url'是正确的,即:将链接到文件'remove_unwanted_files.php'是正确的 – bystwn22