我想删除一个文件AJAX/PHP
。
但php说,我用AJAX发送的文件名不是文件,但是当我直接进入链接时,我可以删除这些文件。看看我当前的PHP,我已经在IF/ELSE语句中检查字符串是否是一个文件:is_file
,结果是false
。
没有is_file
这样说:
Warning: unlink("image.jpg") [function.unlink]: Invalid argument in C:\wamp\www\images\users\delete.php on line 8
文件什么叫Ajax的就是太是文件,我想删除什么文件夹内。
的PHP
<?php
// I save the file sources from the URL what was sent by AJAX to these variables.
$photo_id = $_GET['photo_id'];
$thumbnail_id = $_GET['thumbnail_id'];
function deletePhotos($id){
// If is a file then delete the file.
if(is_file($id)){
return unlink($id);
// Else show error.
} else {
echo $id . " is not a file, or there is a problem with it.<br />" ;
}
}
if(isset($photo_id)){
deletePhotos($photo_id);
}
if(isset($thumbnail_id)){
deletePhotos($thumbnail_id);
}
?>
的AJAX
function deletePhoto(photo, thumbnail){
var photos = encodeURIComponent(photo);
var thumbnails = encodeURIComponent(thumbnail);
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else {// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("media").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET", "http://192.168.2.104/images/users/delete.php?photo_id=\""+photos+"\"&thumbnail_id=\""+thumbnails+"\"", true);
xmlhttp.send();
}
如果这是你的生产脚本,它有一个严重的安全缺陷:任何人都可以告诉脚本删除/取消链接服务器上的任何可写文件 – 2010-08-04 21:52:31