尝试导入CSV时,错误为Warning: fopen(/test-spreadsheet.csv) [function.fopen]: failed to open stream: No such file or directory in /home/.../public_html/wp-content/plugins/bulk-upload/import-response.php on line 49
它还回显了path: /test spreadsheet.csv
,其中我回应了以下内容:
echo "path: " . $file_path;
进口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…</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
}
?>
拉链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;
}
}
}
?>
答案 0 :(得分:0)
这一行:
$file_path = $uploaddir . '/' . basename($_FILES['csv_file']['name']);
我觉得$uploaddir
此时无效,所以不是去正确的目录,而是去根目录(/,而不是/ home ......)
希望这有道理..
您可能只需要:$ud = wp_upload_dir(); $uploaddir = $ud["path"];
就可以了。