jd2007 Posted September 18, 2007 Share Posted September 18, 2007 How to create a file using PHP ? Quote Link to comment https://forums.phpfreaks.com/topic/69732-how-to-create-a-file-using-php/ Share on other sites More sharing options...
AV1611 Posted September 18, 2007 Share Posted September 18, 2007 This is quite easy, even if your question is quite vague... This one reads data from an odbc source, and writes a csv file to the local drive... I just happen to be working on it so I just posted it as is... <?php $Sunday=date('Y-m-d', strtotime("last Sunday")); $OUTPUT=''; //$i=44296; $i=0; $tab='\t'; $file = "./VQTestHistorySS3.TXT"; $fp = fopen($file,"a"); $connect = odbc_connect("QES9000", "", ""); $query = "SELECT itdatshta.`it_date`, itdatshta.`insptype`, itdatshta.`process`, itdatshta.`product`, itdatshta.`serialno`, itdatshta.`failed`, itdatshtda.`descr`, itdatshtda.`hi`, itdatshtda.`lo`, itdatshtda.`units`, itdatshtda.`actual`, itdatshtda.`gonogo`, itdatshtda.`step` FROM `itdatshta` itdatshta INNER JOIN `itdatshtda` itdatshtda ON itdatshta.`datshtid` = itdatshtda.`datshtid` AND itdatshta.`sample` = itdatshtda.`sample` WHERE itdatshta.`product` like 'T%SS3%' AND (itdatshta.`process` = 'VQ Functional Outputs' OR itdatshta.`process` = 'VQ Functional Inputs' OR itdatshta.`process` = 'QA Evaluation' OR itdatshta.`process` = 'Functional Test') AND itdatshta.`failed` = 0 AND itdatshta.`it_date` < {d '$Sunday'} ORDER BY itdatshta.`it_date` ASC, itdatshta.`serialno` ASC, itdatshta.`process` ASC"; $result = odbc_do($connect, $query); WHILE($row=odbc_fetch_array($result)) { $i++; $OUTPUT = $i."\t".rtrim($row['it_date'])."\t".rtrim($row['insptype'])."\t".rtrim($row['process'])."\t".rtrim($row['product'])."\t".rtrim($row['serialno'])."\t".rtrim($row['step'])."\t".rtrim($row['descr'])."\t".rtrim($row['hi'])."\t".rtrim($row['lo'])."\t".rtrim($row['units'])."\t".rtrim($row['actual'])."\t".rtrim($row['gonogo'])."\t YES"; fwrite($fp, $OUTPUT."\n"); } fclose($fp); odbc_close($connect); ?> Quote Link to comment https://forums.phpfreaks.com/topic/69732-how-to-create-a-file-using-php/#findComment-350384 Share on other sites More sharing options...
jitesh Posted September 18, 2007 Share Posted September 18, 2007 fopen("filename.php","w+"); Quote Link to comment https://forums.phpfreaks.com/topic/69732-how-to-create-a-file-using-php/#findComment-350398 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.