繁体   English   中英

如果不存在php,则在其他文件夹中创建txt文件

[英]Create txt files if not exists php, in a different folder

因此,基本上我将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。

我究竟做错了什么?

您正在尝试使用+ cache/"+$cache_file

旁注: +是JS / C ++的连接方法。

它必须是一个点。 另外,请确保已设置短标签。

您还将需要chmod您的文件。

在注释中,您说过使用chmod("cache/".$cache_file, 777); 需要读取为chmod("cache/".$cache_file, 0777);

  • 敲弯,OP使用错误报告,因为我在评论中提出。

OP: 好的,我的错,没有将参数传递给函数!

错误报告添加到文件顶部,这将有助于发现错误。

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

// rest of your code

旁注:错误报告仅应在登台进行,而不应在生产过程中进行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM