尝试导入 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;
导入响应.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
}
?>
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;
}
}
}
?>