0

私は 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

}
?>

最初の電子メールは、何かをさせようとしているだけです。ファイルへのパスは正しいです。

4

2 に答える 2