Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 尝试上载CSV文件时发生fopen错误_Php_Fopen - Fatal编程技术网

Php 尝试上载CSV文件时发生fopen错误

Php 尝试上载CSV文件时发生fopen错误,php,fopen,Php,Fopen,尝试导入CSV时,它会出现以下错误:第49行的/home/../public_html/wp content/plugins/bulk upload/import-response.php中的警告:fopen(/test spreadsheet.CSV)[function.fopen]:无法打开流:没有这样的文件或目录 require_once("zip-util.php"); require_once("script-generator.php"); if ($_PO

尝试导入CSV时,它会出现以下错误:第49行的/home/../public_html/wp content/plugins/bulk upload/import-response.php中的
警告:fopen(/test spreadsheet.CSV)[function.fopen]:无法打开流:没有这样的文件或目录

    require_once("zip-util.php");
    require_once("script-generator.php");

    if ($_POST["verify_bulk_upload_postback"] == "Y")
    {
        if ($_POST["erase_all_data"])
        {
            $query = new WP_Query(array(
                    "post_type" => "people",
                    "posts_per_page" => -1
                ));

            $to_delete = array();
            //echo "<strong>Existed</strong><br /><br />";

            foreach ($query->posts as $post)
            {        
                $to_delete[] = $post->ID;

                if ($post->ID > 0)
                {                
                    $attachment_query = new WP_Query(array(
                        "post_parent" => $post->ID,
                        "posts_per_page" => -1,
                        "post_type" => "attachment"
                    ));

                    foreach($attachment_query->posts as $attachment)
                    {
                        $to_delete[] = $attachment->ID;
                    }
                }                
            }

            foreach ($to_delete as $id)
            {
                //echo "Deleting post with id " . $id . "<br />";
                wp_delete_post($id, true);
            }

        ?><div class="updated"><p><strong><?php _e('Existing Diamonds Deleted'); ?></strong></p></div><?php
        }

        $file_path = $uploaddir . '/' . basename($_FILES['csv_file']['name']);
echo "path: " . $file_path;
        $file = fopen($file_path, 'r');
//echo phpinfo();
        ScriptGenerator::generate($file);

        fclose($file);

        //echo "<br /><strong>Extracting images&hellip;</strong><br /><br />";

        $upload_dir_info = wp_upload_dir();
echo $upload_dir_info["path"];
        ZipUtil::unzip($_FILES["zip_file"]["name"], $upload_dir_info["path"]);

    ?>
    <div class="updated"><p><strong id="status">
        <img src="/wp-content/plugins/bulk-upload/loader.gif" />
        <?php _e('Uploading...'); ?>
    </strong></p></div>

    <?php /* if (count($error_rows) > 0) { ?>
    <div class="error">
        <?php foreach ($error_rows as $error_row) { ?>
            <p>Failed on: <?php print_r($error_row); ?></p>
        <?php } ?>
    </div>
    <?php } */ ?>

<?php

    }

?>
它还有echo的
路径:/test spreadsheet.csv
,我在其中回送了以下内容:

echo "path: " . $file_path;
import-response.php
    require_once("zip-util.php");
    require_once("script-generator.php");

    if ($_POST["verify_bulk_upload_postback"] == "Y")
    {
        if ($_POST["erase_all_data"])
        {
            $query = new WP_Query(array(
                    "post_type" => "people",
                    "posts_per_page" => -1
                ));

            $to_delete = array();
            //echo "<strong>Existed</strong><br /><br />";

            foreach ($query->posts as $post)
            {        
                $to_delete[] = $post->ID;

                if ($post->ID > 0)
                {                
                    $attachment_query = new WP_Query(array(
                        "post_parent" => $post->ID,
                        "posts_per_page" => -1,
                        "post_type" => "attachment"
                    ));

                    foreach($attachment_query->posts as $attachment)
                    {
                        $to_delete[] = $attachment->ID;
                    }
                }                
            }

            foreach ($to_delete as $id)
            {
                //echo "Deleting post with id " . $id . "<br />";
                wp_delete_post($id, true);
            }

        ?><div class="updated"><p><strong><?php _e('Existing Diamonds Deleted'); ?></strong></p></div><?php
        }

        $file_path = $uploaddir . '/' . basename($_FILES['csv_file']['name']);
echo "path: " . $file_path;
        $file = fopen($file_path, 'r');
//echo phpinfo();
        ScriptGenerator::generate($file);

        fclose($file);

        //echo "<br /><strong>Extracting images&hellip;</strong><br /><br />";

        $upload_dir_info = wp_upload_dir();
echo $upload_dir_info["path"];
        ZipUtil::unzip($_FILES["zip_file"]["name"], $upload_dir_info["path"]);

    ?>
    <div class="updated"><p><strong id="status">
        <img src="/wp-content/plugins/bulk-upload/loader.gif" />
        <?php _e('Uploading...'); ?>
    </strong></p></div>

    <?php /* if (count($error_rows) > 0) { ?>
    <div class="error">
        <?php foreach ($error_rows as $error_row) { ?>
            <p>Failed on: <?php print_r($error_row); ?></p>
        <?php } ?>
    </div>
    <?php } */ ?>

<?php

    }

?>
require_once(“zip util.php”);
require_once(“script generator.php”);
如果($\u POST[“验证批量\u上传\u回发”]=“Y”)
{
如果($\u POST[“擦除所有数据”])
{
$query=新的WP\U查询(数组(
“post_type”=>“people”,
“每页帖子”=>-1
));
$to_delete=array();
//回声“存在”

”; foreach($query->posts as$post) { $to_delete[]=$post->ID; 如果($post->ID>0) { $attachment\u query=新的WP\u查询(数组( “post_parent”=>$post->ID, “每页帖子”=>-1, “帖子类型”=>“附件” )); foreach($attachment\u query->posts as$attachment) { $to_delete[]=$attachment->ID; } } } foreach($to_delete as$id) { //回显“删除id为“$id”的帖子。”
; wp_delete_post($id,true); } ?>

在以下位置失败:

zip-util.php

<?php
class ZipUtil
{
    public static function unzip($zip_file, $destination)
    {
        $zip = new ZipArchive();
        $res = $zip->open($zip_file);

        if ($res === TRUE)
        {
            $zip->extractTo($destination);
            $zip->close();
            echo "Images were unzipped.<br />";
        }
        else
        {
            echo "<strong>Failed to unzip images. Please check file permissions.</strong><br />";
    echo "Could not unzip $filename-- ".$res;
    return false;
        }
    }
}


?>

此行:

$file\u path=$uploaddir.'/'.basename($\u FILES['csv\u file']['name']);

我感觉,
$uploaddir
在这一点上是无效的,所以它不是去正确的目录,而是去根目录(/,而不是/home…)

希望这有意义


你可能只需要在上面的一行写上这个:
$ud=wp\u upload\u dir();$uploaddir=$ud[“path”];

echo“path:”.realpath($file\u path);
,然后检查这个目录中是否有
测试电子表格.csv
?谢谢@Winston它刚刚输出了
路径:
:(@Winston:知道它可能是什么吗?@Winston:它没有上传目录中的文件:(dir是空的..dir echos as/home/../public\u html/wp content/uploads/2013/02/test-spreadsheet.csvOK.Write
echo dirname(\u file\uu)
导入response.php
文件中,并向我显示将要输出的路径。同时在此处写入从根目录(其中是
index.php
)到
测试电子表格.csv
文件的路径,并将其显示出来。谢谢,但现在
警告:fopen(数组/测试电子表格.csv)…
我现在已经修改了这个Dave,但我不确定它是否会起作用..但我认为假设
$uploaddir
是错误的是正确的,但我不确定应该怎么做..很好…达到了目的!现在
警告:fopen(/home/../public\u html/wp content/uploads/2013/02/test spreadsheet.csv)
好吧,我不完全理解发生了什么,但我建议你
打印($\u文件)
看看存储文件的目录是否在那里,理论上应该在那里,但不要让我这么认为!
数组([csv\u文件]=>数组([name]=>test-spreadsheet.csv[type]=>文本/逗号分隔值[tmp\u name]=>/tmp/phpAQk652[error]=>0[size]=>162[zip\u文件]=>Array([name]=>[type]=>[tmp\u name]=>[error]=>4[size]=>0))
我已经将代码从
name
编辑到
tmp\u name
    require_once("zip-util.php");
    require_once("script-generator.php");

    if ($_POST["verify_bulk_upload_postback"] == "Y")
    {
        if ($_POST["erase_all_data"])
        {
            $query = new WP_Query(array(
                    "post_type" => "people",
                    "posts_per_page" => -1
                ));

            $to_delete = array();
            //echo "<strong>Existed</strong><br /><br />";

            foreach ($query->posts as $post)
            {        
                $to_delete[] = $post->ID;

                if ($post->ID > 0)
                {                
                    $attachment_query = new WP_Query(array(
                        "post_parent" => $post->ID,
                        "posts_per_page" => -1,
                        "post_type" => "attachment"
                    ));

                    foreach($attachment_query->posts as $attachment)
                    {
                        $to_delete[] = $attachment->ID;
                    }
                }                
            }

            foreach ($to_delete as $id)
            {
                //echo "Deleting post with id " . $id . "<br />";
                wp_delete_post($id, true);
            }

        ?><div class="updated"><p><strong><?php _e('Existing Diamonds Deleted'); ?></strong></p></div><?php
        }

        $file_path = $uploaddir . '/' . basename($_FILES['csv_file']['name']);
echo "path: " . $file_path;
        $file = fopen($file_path, 'r');
//echo phpinfo();
        ScriptGenerator::generate($file);

        fclose($file);

        //echo "<br /><strong>Extracting images&hellip;</strong><br /><br />";

        $upload_dir_info = wp_upload_dir();
echo $upload_dir_info["path"];
        ZipUtil::unzip($_FILES["zip_file"]["name"], $upload_dir_info["path"]);

    ?>
    <div class="updated"><p><strong id="status">
        <img src="/wp-content/plugins/bulk-upload/loader.gif" />
        <?php _e('Uploading...'); ?>
    </strong></p></div>

    <?php /* if (count($error_rows) > 0) { ?>
    <div class="error">
        <?php foreach ($error_rows as $error_row) { ?>
            <p>Failed on: <?php print_r($error_row); ?></p>
        <?php } ?>
    </div>
    <?php } */ ?>

<?php

    }

?>