简体   繁体   English

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

[英]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);

  • The clincher, OP used error reporting as I suggested in comments. 敲弯,OP使用错误报告,因为我在评论中提出。

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.

相关问题 阅读文件夹中几个txt文件的行,并创建一个包含所有文本行的单个文本文件 - Read the lines of several txt files that are inside a folder and create a single text file containing all lines of text 检查输入文件夹是否存在于PHP或JavaScript中 - Check if an input folder exists or not in PHP or JavaScript 从多个txt文件创建JSON文件 - Create JSON file from multiple txt files 在子文件夹中创建txt文件列表文件 - Create txt file listing files in subfolders 避免 Chrome 保存 .txt 和 .php 文件缓存 - Avoid Chrome saving .txt and .php files to cache 如何使用Java脚本打印文件夹内的所有txt文件 - How to print all the txt files inside a folder using java script 是否可以仅使用客户端创建txt文件? …但是到特定的文件夹 - Is it possible to create txt file using only client side ? … but to a specific folder 创建公用文件夹并允许用户在特定文件夹中创建文件 - create public folder and allow user to create files into the particular folder 用于识别文件夹是否存在以及是否未在 Google 云端硬盘中创建的脚本 - Script to identify if a folder exists and if it does not create it in Google Drive 当一个文件夹已经存在时,Multer 试图创建一个新文件夹 - Multer trying to create a new folder when one already exists
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM