2013-07-02 2 views
-1

나는이에 터치,하지만 운, 메신저 희망 누군가가PHP 저장 CSV 서버에 파일 로컬이 아닌

내 파일을 도울 수있는 몇 가지 게시물을 포럼을 검색하고 발견 내가 저장할 수있는 CSV 파일을 생성 바탕 화면에, 나는 ..

$filename="citylink"; $directory = "/httpdocs/citylink"; 
$csv_filename = $filename."_".date("Y-m-d_H-i",time()).".csv"; 

$fd = fopen ("$directory" . $csv_filename, "w"); 

echo fputs($fd); 

fclose($fd); 

을 시도하지만 난이 올바른 장소에 넣어 havent 한 확실히 운이 메신저를 받고되지 않은

citylink 우리의 웹 서버의 디렉토리에 저장하는 파일을/필요

어떤 도움을 많이

사전에

`

<?php 

require('includes/application_top.php'); 

// csv settings 

define("CSV_SEPARATOR", ","); 
define("CSV_NEWLINE", "\r\n"); 


//csv dump info 

$filename="citylink"; $directory = "/httpdocs/citylink"; 
$csv_filename = $filename."_".date("Y-m-d_H-i",time()).".csv"; 

$fd = fopen ("$directory" . $csv_filename, "w"); 

echo fputs($fd); 

fclose($fd); 


// not submitted, so show form to submit 

if (! $_POST['submitted'] && ! $_POST['submitted' == 1 ]) { 
?> 
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html <?php echo HTML_PARAMS; ?>> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>"> 
<title><?php echo TITLE; ?></title> 
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css"> 
<link rel="stylesheet" type="text/css" href="includes/cssjsmenuhover.css" media="all" id="hoverJS"> 
<script language="javascript" src="includes/menu.js"></script> 
<script language="javascript" src="includes/general.js"></script> 
<script type="text/javascript"> 
    <!-- 
    function init() 
    { 
    cssjsmenu('navbar'); 
    if (document.getElementById) 
    { 
     var kill = document.getElementById('hoverJS'); 
     kill.disabled = true; 
    } 
    } 
    // --> 
</script> 
</head> 
<body onLoad="init()"> 
<!-- header //--> 
<?php require(DIR_WS_INCLUDES . 'header.php'); ?> 
<!-- header_eof //--> 

<!-- body //--> 
<table border="0" width="100%" cellspacing="2" cellpadding="2"> 
    <tr> 
<td> 
    <div class="pageHeading"><?php echo 'City Link - Send Jobs To Xtend'; ?></div> 

<br><br> 

    <form method="post" action="<?php echo $PHP_SELF;?>"> 
    <table border="0" cellpadding="3"> 
    <tr> 
    <td><?php echo 'Start From Invoice'; ?></td> 
    <td><input name="start" size="5" value="<?php echo (int)$_POST['start']; ?>"> 
    </tr> 
    <tr> 
    <td><?php echo 'End Invoice'; ?></td> 
    <td><input name="end" size="5" value="<?php echo (int)$_POST['end']; ?>"> 
    </tr> 
    <tr> 
    <td>&nbsp;</td> 
    <td><input type="submit" value="<?php echo 'Send File To X-tend'; ?>"></td> 
    </tr> 
    </table> 
    <input type="hidden" name="submitted" value="1"> 
    </form> 

</td> 
    </tr> 
</table> 
<!-- body_eof //--> 

<!-- footer //--> 
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?> 
<!-- footer_eof //--> 
</body> 
</html> 
<?php 
} 
// submitted so generate csv 
else 
{ 
    generatecsv((int)$_POST['start'], (int)$_POST['end']); 

} 
require(DIR_WS_INCLUDES . 'application_bottom.php'); 


// generates csv file from $start order to $end order, inclusive 
function generatecsv($start, $end) 
{ 
    global $db; 

    $sql = "SELECT * FROM " . TABLE_ORDERS . " 
      WHERE orders_id >= :start: 
      AND orders_id <= :end:"; 
    $sql = $db->bindVars($sql, ':start:', $start, 'integer'); 
    $sql = $db->bindVars($sql, ':end:', $end, 'integer'); 
    $orders = $db->Execute($sql); 

    header("Pragma: cache"); 
    header("Content-Type: text/comma-separated-values"); 
    header("Content-Disposition: attachment; filename=" . 'city_link_export.csv'); 


    while (!$orders->EOF) 
    { 
    $codes_lookup = get_country_and_zone_code($orders->fields['delivery_country'], $orders->fields['delivery_state']); 
    { 
     list($country, $province) = $codes_lookup; 


     //CSV OUTPUT FILE 


     echo quote($orders->fields['orders_id']).CSV_SEPARATOR; 
     echo quote($orders->fields['customers_id']).CSV_SEPARATOR; 
     echo quote($orders->fields['delivery_name']).CSV_SEPARATOR; 
     echo quote($orders->fields['delivery_street_address']).CSV_SEPARATOR; 
     echo quote($orders->fields['delivery_suburb']).CSV_SEPARATOR; 
     echo quote('').CSV_SEPARATOR; // Address Line3 
     echo quote($orders->fields['delivery_city']).CSV_SEPARATOR; 
     echo quote($orders->fields['delivery_state']).CSV_SEPARATOR; 
     echo quote($orders->fields['delivery_postcode']).CSV_SEPARATOR; 
     echo quote($orders->fields['customers_telephone']).CSV_SEPARATOR; 
     echo quote('').CSV_SEPARATOR; //email address not included becauce of amazon emails 
     echo quote($orders->fields['date_purchased']).CSV_SEPARATOR; 
     echo quote('107').CSV_SEPARATOR; //service level 
     echo quote('9').CSV_SEPARATOR; // default pacel weight 
     echo quote('1').CSV_SEPARATOR; // default no of parcels 
     echo quote('J1').CSV_SEPARATOR; // default package description 
     echo quote($orders->fields['delivery_name']).CSV_SEPARATOR; 
     echo quote('').CSV_SEPARATOR; // bulk name 
     echo quote('').CSV_SEPARATOR; // consignment number 
     echo quote('8108991').CSV_SEPARATOR; // city link account number 
     echo quote('').CSV_SEPARATOR; // special delivery instructions 
     echo quote('OYPLA').CSV_SEPARATOR; // Description of goods (mandatory for Irish deliveries 
     echo quote('').CSV_SEPARATOR; // printer mappinng 
     echo quote('N').CSV_SEPARATOR; // saturday delivery Y/N 
     echo quote('N').CSV_SEPARATOR; // return shipment Y/N 
     echo quote('').CSV_SEPARATOR; // default payment on delivery ammount 
     echo quote('').CSV_SEPARATOR; // default value of goods ammount 
     echo quote('').CSV_SEPARATOR; // PDN, pre delivery notification 
     echo quote('N').CSV_SEPARATOR; // Exchange Marker 

     echo quote().CSV_NEWLINE; 

    } 



    $orders->MoveNext(); 

    } 
} 

// returns the name for a shipping status 
function getorderstatus($statusid) 
{ 
    global $db; 
    $query = "select * from " . TABLE_ORDERS_STATUS . " where orders_status_id = $statusid"; 
    $statii = $db->Execute($query); 
    while (!$statii->EOF) { 
    return $statii->fields['orders_status_name']; 
    } 

    return $statusid; 
} 

// formats a value suitable for including in a csv file 
function quote($value) 
{ 
    // if quote mark in string then escape with another quote mark 
    // then put inside quote marks and return 
    if (strstr($value, '"') !== FALSE) 
    { 
    $value = str_replace('"', '""', $value); 
    return '"$value"'; 
    } 

    // if separator in string then put inside quote marks 
    if (strstr($value, CSV_SEPARATOR) !== FALSE) 
    { 
    return '"$value"'; 
    } 

    return $value; 
} 

    function get_country_and_zone_code($country_name, $zone_name) { 
    global $db; 
    $sql = "select countries_id, countries_name, countries_iso_code_2, countries_iso_code_3 
      from " . TABLE_COUNTRIES . " 
      where countries_name = :ctryname: "; 
    $sql = $db->bindVars($sql, ':ctryname:', $country_name, 'string'); 
    $result1 = $db->Execute($sql); 
    if ($result1->RecordCount() == 0) return 'BAD'; 
    $sql = "select zone_code, zone_id, zone_name 
      from " . TABLE_ZONES . " 
      where zone_country_id = :ctryid: 
      and zone_name = :zonename:"; 
    $sql = $db->bindVars($sql, ':ctryid:', $result1->fields['countries_id'], 'integer'); 
    $sql = $db->bindVars($sql, ':zonename:', $zone_name, 'string'); 
    $result2 = $db->Execute($sql); 

    if ($result2->RecordCount() == 0) { 
     return 'BAD'; 
    } else { 
     return array($result1->fields['countries_iso_code_2'], $result2->fields['zone_code']); 
    } 
    } 



?> 

`

+0

코드가 이제는// 디렉토리 뒤에 /가 없으므로 파일을'/ httpdocs/citylinkcitylink_ .csv'에 쓰려고합니다. –

+0

쓰기 권한을 확인하고 경로가 올바른지 확인하십시오. – steven

답변

1

이 부분은 잘못

전체

러셀 감사합니다 감사합니다 :

,536,
$filename="citylink"; $directory = "/httpdocs/citylink"; 
$csv_filename = $filename."_".date("Y-m-d_H-i",time()).".csv"; 

$fd = fopen ("$directory" . $csv_filename, "w"); 

$directory$csv_filename을 디렉토리 분리 기호없이 연결합니다. 결과는 다음과 같습니다. /httpdocs/citylinkcitylink_Y-m-d_H-i.csv - 아마도 잘못된 것입니다.

사용 : $fd = fopen ("$directory/$csv_filename", "w");

이 두 번째로, 당신은 당신의 $directory를 확인해야 올바른 절대 경로입니다. 100 % 확실하지 않은 경우 상대 경로를 사용할 수 있습니다 (THIS 파일과 관련 있음).

관련 문제