[英]Create txt files if not exists php, in a different folder
So basicly I got my php script in one folder, I want to create a txt file in /cache if the file does not exist already. 因此,基本上我将php脚本保存在一个文件夹中,如果该文件尚不存在,我想在/ cache中创建一个txt文件。 if it exists it should just abort and continue with the rest of the script.
如果存在,则应中止并继续执行脚本的其余部分。
$(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();
}
});
});
and in my instagram_feed.php i now tried with: 在我的instagram_feed.php中,我现在尝试使用:
$cache_file = $_POST['cache_file'];
$fh = fopen("cache/"+$cache_file, 'w') or die("fail");
and it returns fail... I got chmod 777 on the cache folder aswell. 它返回失败...我在高速缓存文件夹上也有chmod 777。
What am I doing wrong? 我究竟做错了什么?
You're trying to concatenate with a +
here cache/"+$cache_file
. 您正在尝试使用
+
cache/"+$cache_file
。
Sidenote: The +
is the JS/C++ concatenate method. 旁注:
+
是JS / C ++的连接方法。
It needs to be a dot. 它必须是一个点。 Plus, make sure short tags are set.
另外,请确保已设置短标签。
You will need to chmod your files also. 您还将需要chmod您的文件。
In comments you said you used chmod("cache/".$cache_file, 777);
在注释中,您说过使用
chmod("cache/".$cache_file, 777);
that needs to read as chmod("cache/".$cache_file, 0777);
需要读取为
chmod("cache/".$cache_file, 0777);
OP: Ok my fault, didnt pass the parameter to the function! OP: 好的,我的错,没有将参数传递给函数!
Add error reporting to the top of your file(s) which will help find errors. 将错误报告添加到文件顶部,这将有助于发现错误。
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// rest of your code
Sidenote: Error reporting should only be done in staging, and never production. 旁注:错误报告仅应在登台进行,而不应在生产过程中进行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.