基本上我把php脚本放在一个文件夹中,如果文件不存在,我想在/ cache中创建一个txt文件。如果它存在,它应该中止并继续脚本的其余部分。
$(document).ready(function() {
var feed = $("#instagramFeed .wrap");
$.ajax({
type: "POST",
url: "<?= path("instagram_feed.php"); ?>",
data: { feed_url: "http://iconosquare.com/feed/<?= $butikInstagram ?>", instagram_url: "http://instagram.com/<?= $butikInstagram ?>", cache_file: "<?= $butikInstagram ?>.txt" },
success: function(data) {
console.log("SUCCESS");
feed.html(data).find("img").show();
}
});
});
在我的instagram_feed.php中,我现在尝试使用:
$cache_file = $_POST['cache_file'];
$fh = fopen("cache/"+$cache_file, 'w') or die("fail");
然后它返回失败...我在缓存文件夹上也得到了chmod 777。
我做错了什么?
答案 0 :(得分:3)
您尝试使用此+
cache/"+$cache_file
进行连接。
旁注: +
是JS / C ++连接方法。
它需要是一个点。另外,确保设置短标签。
您还需要chmod您的文件。
在评论中,您说您使用chmod("cache/".$cache_file, 777);
需要阅读为chmod("cache/".$cache_file, 0777);
OP:好我的错,没有将参数传递给函数!
将error reporting添加到文件的顶部,这有助于查找错误。
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// rest of your code
旁注:错误报告应仅在暂存时完成,而不是生产。