将文件保存在服务器内的特定目录上,而不是下载文件

时间:2016-11-07 14:59:39

标签: php csv export internal

我试图更改以下脚本,该脚本可以正常工作并保存相同的文件,但是在服务器内部位置,而不是现在正在执行保存文件,然后上传到我的目的地。

<?php
    session_start();
    include("includes/config.inc2.php");
    @ini_set('display_errors','Off');
    $quantity_store_query = ''; $quantity_store_query1 = '';
    if(isset($_REQUEST['store_id']) && $_REQUEST['store_id'] != '')
    {
        $get_t = mysql_fetch_array(mysql_query("select quantity_store_id from tbl_website where `store_id` = '".$_REQUEST['store_id']."'"));
        $quantity_store_query =  " pq.quantity_store_id = '".$get_t['quantity_store_id']."' and ";
        $quantity_store_query1 =  " quantity_store_id = '".$get_t['quantity_store_id']."' and ";

        $get_cur = mysql_fetch_array(mysql_query("SELECT currencies_id FROM currencies WHERE code = (SELECT currency FROM tbl_store WHERE store_id = {$_REQUEST['store_id']})"));
        $currency = $get_cur['currencies_id'];
    }
    if(isset($_REQUEST['lowstock']) && $_REQUEST['lowstock'] != '')
    {   
        define("MINI_ITMS_STOCK",5);

        $data='';
        $csv_output="";
        $refundquery = mysql_query("select p.product_name,p.product_code,p.product_desc,p.weight,p.was_price,p.quantity,p.id,p.created_dt from product as p,product_quantity as pq where ".$quantity_store_query."  p.id = pq.product_id and pq.`quantity` <= '".MINI_ITMS_STOCK."' group by pq.product_id order by p.created_dt") or die(mysql_error());
        if(mysql_num_rows($refundquery) > 0)    
        {
            $row1 = array("Item Name", "Item Code", "Description", "Weight", "Colour", "Size", "Wholesale Price", "Image1", "Image2", "Image3", "Image4", "Image5", "Quantity");
            foreach ($row1 as $value1 ) 
            {
                $data .= $value1."\t";
            }
            $data .= "\n";
            for($p=0;$p<mysql_num_rows($refundquery);$p++)
            {
                $orderinfo = mysql_fetch_array($refundquery);
                $prod_id = $orderinfo['id'];
                $product_name = stripslashes($orderinfo['product_name']);
                $product_code = stripslashes($orderinfo['product_code']);
                $product_desc = strip_tags(stripslashes($orderinfo['product_desc']));
                $weight = stripslashes($orderinfo['weight']);
                $was_price = get_table_data("product_price","price","product_id=".$prod_id." AND store_id=".$_REQUEST['store_id'] . " AND currencies_id = $currency");
                $colour_name = 'N/A';
                $size_name = 'N/A';         
                $quantity = $info['quantity'];
                $barcode = $info['barcode'];
                $psql = mysql_query("SELECT * FROM `product_quantity` where ".$quantity_store_query1." product_id = '$prod_id' and `quantity` <= '".MINI_ITMS_STOCK."' LIMIT 12") or die(mysql_error());
                if(mysql_num_rows($psql) > 0)
                {
                    for($k=0;$k<mysql_num_rows($psql);$k++)
                    {
                        $kinfo = mysql_fetch_array($psql);
                        $colour_name = get_table_data("attributes_value","attr_value1","attribute_value_id=".$kinfo['color_id']);
                        $size_name = get_table_data("attributes_value","attr_value1","attribute_value_id=".$kinfo['size_id']);
                        $images = get_image_data($prod_id,$kinfo['color_id']);
                        $quantity = $kinfo['quantity'];
                        $barcode = $kinfo['barcode'];
                        if($quantity <= MINI_ITMS_STOCK)
                        {
                            $export=array($product_name,$product_code,$barcode,$product_desc,$weight,$colour_name,$size_name,$was_price,$images[0], $images[1], $images[2], $images[3], $images[4],$quantity);
                            for($i=0; $i<count($export); $i++)
                            {
                            $line = ''; $value='';
                                $value=$export[$i];
                                if ((!isset($value)) OR ($value == "")) {
                                    $value = "\t"; 
                                } 
                                else 
                                {
                                    $value = '"' . $value . '"' . "\t"; 
                                }
                                $line .= stripslashes($value);
                            $csv_output .= trim($line)."\t";
                        }
                            $csv_output .= "\n";
                        }
                    }
                }
                else
                {
                    $p_sql = mysql_query("SELECT * FROM `product` where id = $prod_id and quantity  <= ".MINI_ITMS_STOCK." and is_color = 0 and is_size = 0");
                    if(mysql_num_rows($p_sql) > 0)
                    {   
                        $kinfo = mysql_fetch_array($p_sql);
                        $images = get_image_data($prod_id,0);
                        $export=array($product_name,$product_code,$barcode,$product_desc,$weight,$colour_name,$size_name,$was_price,$images[0], $images[1], $images[2], $images[3], $images[4],$quantity);
                        for($i=0; $i<count($export); $i++)
                        {
                $line = ''; $value='';
                    $value=$export[$i];
                    if ((!isset($value)) OR ($value == "")) {
                        $value = "\t"; 
                    } 
                    else 
                    {
                        $value = '"' . $value . '"' . "\t"; 
                    }
                    $line .= stripslashes($value);

                $csv_output .= trim($line)."\t";
            }$csv_output .= "\n";
                    }
                }
            }

            $data = str_replace("\r","",$data);
            $to_date = date("d-m-y-h-i-s");
            $excel_name = "Low_stock_".$to_date;
            header("Content-Type: application/vnd.ms-excel");
            header("Content-Disposition: attachment; filename=\"".$excel_name.".xls\"");
            header("Pragma: no-cache");
            header("Expires: 0");
            print $data.$csv_output;
            exit;
        }
    }
    if(isset($_REQUEST['outofstock']) && $_REQUEST['outofstock'] != '')
    {   
        define("MINI_ITMS_STOCK",0);
        $data='';
        $csv_output="";
        $refundquery = mysql_query("select p.product_name,p.product_code,p.product_desc,p.weight,p.was_price,p.quantity,p.id,p.created_dt from product as p,product_quantity as pq where ".$quantity_store_query." p.id = pq.product_id and pq.`quantity` <= '".MINI_ITMS_STOCK."' group by pq.product_id order by p.created_dt") or die(mysql_error());
        if(mysql_num_rows($refundquery) > 0)    
        {
            $row1 = array("Item Name", "Item Code", "Barcode", "Description", "Weight", "Colour", "Size", "Wholesale Price", "Image1", "Image2", "Image3", "Image4", "Image5", "Quantity");
            foreach ($row1 as $value1 ) 
            {
                $data .= $value1."\t";
            }
            $data .= "\n";
            for($p=0;$p<mysql_num_rows($refundquery);$p++)
            {
                $orderinfo = mysql_fetch_array($refundquery);
                $prod_id = $orderinfo['id'];
                $product_name = stripslashes($orderinfo['product_name']);
                $product_code = stripslashes($orderinfo['product_code']);
                $product_desc = strip_tags(stripslashes($orderinfo['product_desc']));
                $weight = stripslashes($orderinfo['weight']);
                $was_price = get_table_data("product_price","price","product_id=".$prod_id." AND store_id=".$_REQUEST['store_id'] . " AND currencies_id = $currency");
                $colour_name = 'N/A';
                $size_name = 'N/A';         
                $quantity = $info['quantity'];
                $barcode = $info['barcode'];
                $psql = mysql_query("SELECT * FROM `product_quantity` where ".$quantity_store_query1." product_id = '$prod_id' and `quantity` <= '".MINI_ITMS_STOCK."'") or die(mysql_error());
                if(mysql_num_rows($psql) > 0)
                {
                    for($k=0;$k<mysql_num_rows($psql);$k++)
                    {
                        $kinfo = mysql_fetch_array($psql);
                        $colour_name = get_table_data("attributes_value","attr_value1","attribute_value_id=".$kinfo['color_id']);
                        $size_name = get_table_data("attributes_value","attr_value1","attribute_value_id=".$kinfo['size_id']);
                        $images = get_image_data($prod_id,$kinfo['color_id']);
                        $quantity = $kinfo['quantity'];
                        $barcode = $kinfo['barcode'];
                        if($quantity <= MINI_ITMS_STOCK)
                        {
                            $export=array($product_name,$product_code,$barcode,$product_desc,$weight,$colour_name,$size_name,$was_price,$images[0], $images[1], $images[2], $images[3], $images[4],$quantity);
                            for($i=0; $i<count($export); $i++)
                            {
                            $line = ''; $value='';
                                $value=$export[$i];
                                if ((!isset($value)) OR ($value == "")) {
                                    $value = "\t"; 
                                } 
                                else 
                                {
                                    $value = '"' . $value . '"' . "\t"; 
                                }
                                $line .= stripslashes($value);
                            $csv_output .= trim($line)."\t";
                        }
                            $csv_output .= "\n";
                        }
                    }
                }
                else
                {
                    $p_sql = mysql_query("SELECT * FROM `product` where id = $prod_id and quantity  <= ".MINI_ITMS_STOCK." and is_color = 0 and is_size = 0");
                    if(mysql_num_rows($p_sql) > 0)
                    {   
                        $kinfo = mysql_fetch_array($p_sql);
                        $images = get_image_data($prod_id,0);
                        $export=array($product_name,$product_code,$barcode,$product_desc,$weight,$colour_name,$size_name,$was_price,$images[0], $images[1], $images[2], $images[3], $images[4],$quantity);
                        for($i=0; $i<count($export); $i++)
                        {
                $line = ''; $value='';
                    $value=$export[$i];
                    if ((!isset($value)) OR ($value == "")) {
                        $value = "\t"; 
                    } 
                    else 
                    {
                        $value = '"' . $value . '"' . "\t"; 
                    }
                    $line .= stripslashes($value);

                $csv_output .= trim($line)."\t";
            }$csv_output .= "\n";
                    }
                }
            }

            $data = str_replace("\r","",$data);
            $to_date = date("d-m-y-h-i-s");
            $excel_name = "Out_Of_stock_".$to_date;
            header("Content-Type: application/vnd.ms-excel");
            header("Content-Disposition: attachment; filename=\"".$excel_name.".xls\"");
            header("Pragma: no-cache");
            header("Expires: 0");
            print $data.$csv_output;
            exit;
        }
    }
    if(isset($_REQUEST['stock']) && $_REQUEST['stock'] != '')
    {   
        define("MINI_ITMS_STOCK",'-1');
        $data='';
        $csv_output="";
        $refundquery = mysql_query("select p.main_category_name,p.sub_category_name,p.item_collection,p.product_name,p.product_code,p.product_desc,p.weight,p.was_price,p.quantity,p.id,p.created_dt from product as p,product_quantity as pq where ".$quantity_store_query." p.id = pq.product_id and pq.`quantity` >= '".MINI_ITMS_STOCK."' group by pq.product_id order by p.created_dt") or die(mysql_error());
        if(mysql_num_rows($refundquery) > 0)    
        {
            $row1 = array("Main Category","Sub Category","Item Collection","Item Name", "Item Code", "Stock Code", "Barcode", "Description", "Weight", "Colour", "Size", "Wholesale Price", "RRP", "Image1", "Image2", "Image3", "Image4", "Image5", "Quantity", "Quantity Code");
            foreach ($row1 as $value1 ) 
            {
                $data .= $value1."\t";
            }
            $data .= "\n";
            for($p=0;$p<mysql_num_rows($refundquery);$p++)
            {
                $orderinfo = mysql_fetch_array($refundquery);
                $prod_id = $orderinfo['id'];
                $product_name = stripslashes($orderinfo['product_name']);
                $product_code = stripslashes($orderinfo['product_code']);
                $product_desc = strip_tags(stripslashes($orderinfo['product_desc']));
                $item_collection = stripslashes($orderinfo['item_collection']);
                $main_category_name = stripslashes($orderinfo['main_category_name']);
                $sub_category_name = stripslashes($orderinfo['sub_category_name']);
                $weight = stripslashes($orderinfo['weight']);
                $was_price = get_table_data("product_price","price","product_id=".$prod_id." AND store_id=".$_REQUEST['store_id'] . " AND currencies_id = $currency");
                $was_active = get_table_data("product_website","active","product_id=".$prod_id." AND store_id=".$_REQUEST['store_id'] . "");
                $colour_name = 'N/A';
                $size_name = 'N/A';         
                $quantity = $info['quantity'];
                $barcode = $info['barcode'];
                $psql = mysql_query("SELECT * FROM `product_quantity` where ".$quantity_store_query1." product_id = '$prod_id' and `quantity` >= '".MINI_ITMS_STOCK."'") or die(mysql_error());
                $psql2 = mysql_query("SELECT * FROM `product_category` where product_id = $prod_id");
                if(mysql_num_rows($psql) > 0)
                if($was_active == 1)
                {
                    for($k=0;$k<mysql_num_rows($psql);$k++)
                    {
                        $kinfo = mysql_fetch_array($psql);
                        $kinfo2 = mysql_fetch_array($psql2);
                        $category_name = get_table_data("category","cat_name","cat_id=".$kinfo2['category_id']);
                        $colour_name = get_table_data("attributes_value","attr_value1","attribute_value_id=".$kinfo['color_id']);
                        $size_name = get_table_data("attributes_value","attr_value1","attribute_value_id=".$kinfo['size_id']);
                        $images = get_image_data($prod_id,$kinfo['color_id']);
                        $quantity = $kinfo['quantity'];
                        $barcode = $kinfo['barcode'];
                        $RRP = ceil($was_price * 2.5);

                        ?>
<?php
if ($quantity > 5) { 
$quantity_code = 2;
} elseif ($quantity < 5) {
$quantity_code = 1;
} elseif ($quantity = 0){
$quantity_code = 0;
?>
<?php
                            $export=array($main_category_name,$sub_category_name,$item_collection,$product_name,$product_code,$product_code.$colour_name.$size_name,$barcode,$product_desc,$weight,$colour_name,$size_name,$was_price,$RRP,$images[0], $images[1], $images[2], $images[3], $images[4],$quantity,$quantity_code);
                            for($i=0; $i<count($export); $i++)
                            {
                            $line = ''; $value='';
                                $value=$export[$i];
                                if ((!isset($value)) OR ($value == "")) {
                                    $value = "\t"; 
                                } 
                                else 
                                {
                                    $value = '"' . $value . '"' . "\t"; 
                                }
                                $line .= stripslashes($value);
                            $csv_output .= trim($line)."\t";
                        }
                            $csv_output .= "\n";
                        }
                    }
                }
                else
                {
                    $p_sql = mysql_query("SELECT * FROM `product` where id = $prod_id and quantity  >= ".MINI_ITMS_STOCK." and is_color = 0 and is_size = 0");
                    if(mysql_num_rows($p_sql) > 0)
                    if($was_active == 1)
                    {   
                        $kinfo = mysql_fetch_array($p_sql);
                        $images = get_image_data($prod_id,0);
                        $export=array($main_category_name,$sub_category_name,$item_collection,$category_name,$product_name,$product_code,$product_code.$colour_name.$size_name,$barcode,$product_desc,$weight,$colour_name,$size_name,$was_price,$RRP,$images[0], $images[1], $images[2], $images[3], $images[4],$quantity,$quantity_code);
                        for($i=0; $i<count($export); $i++)
                                        {
                                $line = ''; $value='';
                                    $value=$export[$i];
                                    if ((!isset($value)) OR ($value == "")) {
                                        $value = "\t"; 
                                    } 
                                    else 
                                    {
                                        $value = '"' . $value . '"' . "\t"; 
                                    }
                                    $line .= stripslashes($value);

                                $csv_output .= trim($line)."\t";
                            }$csv_output .= "\n";
                    }
                }
            }

            $data = str_replace("\r","",$data);
            $to_date = date("d-m-y-h-i-s");
            $excel_name = "BANNED_STOCK_UPDATE";
            header("Content-Type: application/vnd.ms-excel");
            header("Content-Disposition: attachment; filename=\"".$excel_name.".xls\"");
            header("Pragma: no-cache");
            header("Expires: 0");
            print $data.$csv_output;
            exit;
        }
    }
?>

0 个答案:

没有答案