redarrow Posted October 16, 2008 Share Posted October 16, 2008 Advance thank you... switch not working on FALSE1 anybody..... <?php if(isset($_POST['submit'])){ $new_doc=trim($_POST['new_doc']); $file_name=trim($_POST['file_name']); $cheek=$_POST['cheek']; $error=$_POST['error']; if( empty($new_doc) && empty($file_name) ){ $error='FALSE1'; } $cheek=substr($file_name,-4); if($cheek !='.doc') { $error='FALSE2'; } $x=glob("*.*"); if(in_array($file_name,$x)){ $error='FALSE3'; } $fh=@fopen($file_name, 'w+'); @fwrite($fh, $new_doc); @fclose($fh); } switch($error){ CASE "FALSE1": echo "<center>PLEASE TRY AGIN THERE WAS A PROBLAM! <br><br> Make sure you fill in all the form. <br><br> </center>"; BREAK; CASE "FALSE2": echo "<center>PLEASE TRY AGIN THERE WAS A PROBLAM! <br><br> Make sure the name of the file is a .doc. <br><br> </center>"; BREAK; CASE "FALSE3": echo "<center>PLEASE TRY AGIN THERE WAS A PROBLAM! <br><br> Sorry we have that file name!. <br><br> </center>"; BREAK; } ?> <center> <form method="POST" action="<?php $_SERVER['PHP_SELF']; ?>"> <br> <br> Please name the file .doc <br> <br> <input type="text" name="file_name"> <br> <br> Please write your text <br> <br> <textarea name="new_doc" cols="30" rows="20"> </textarea> <br> <br> <input type="submit" name="submit" value="Export to Word"> <br><br> </form> </center> Quote Link to comment https://forums.phpfreaks.com/topic/128770-solved-switch-not-working-properly-please-help/ Share on other sites More sharing options...
GingerRobot Posted October 16, 2008 Share Posted October 16, 2008 With over 5000 posts, I would have thought you'd have realised that we need a touch more than 'not working' to help diagnose a problem. Quote Link to comment https://forums.phpfreaks.com/topic/128770-solved-switch-not-working-properly-please-help/#findComment-667525 Share on other sites More sharing options...
redarrow Posted October 16, 2008 Author Share Posted October 16, 2008 code all works except the first swich condition that it........ <?php if(isset($_POST['submit'])){ $new_doc=trim($_POST['new_doc']); $file_name=strtolower(strtoupper(trim($_POST['file_name']))); $cheek=$_POST['cheek']; $error=$_POST['error']; if( empty($new_doc) && empty($file_name) ){ $error='FALSE'; } $cheek=substr($file_name,-4); if($cheek !='.doc') { $error='FALSE2'; } $x=glob("*.*"); if(in_array($file_name,$x)){ $error='FALSE3'; } if(!$error){ $fh=@fopen($file_name, 'w+'); @fwrite($fh, $new_doc); @fclose($fh); echo "<center>THANK YOU FILE CREATED AS A WORD DOCUMENT!</center>"; } } switch($error){ CASE "FALSE": echo "<center>PLEASE TRY AGIN THERE WAS A PROBLAM! <br><br> Make sure you fill in all the form. <br><br> </center>"; BREAK; CASE "FALSE2": echo "<center>PLEASE TRY AGIN THERE WAS A PROBLAM! <br><br> Make sure the name of the file is a .doc. <br><br> </center>"; BREAK; CASE "FALSE3": echo "<center>PLEASE TRY AGIN THERE WAS A PROBLAM! <br><br> Sorry we have that file name!. <br><br> </center>"; BREAK; } ?> <center> <form method="POST" action="<?php $_SERVER['PHP_SELF']; ?>"> <br> <br> Please name the file .doc <br> <br> <input type="text" name="file_name"> <br> <br> Please write your text <br> <br> <textarea name="new_doc" cols="30" rows="20"> </textarea> <br> <br> <input type="submit" name="submit" value="Export to Word"> <br><br> </form> </center> Quote Link to comment https://forums.phpfreaks.com/topic/128770-solved-switch-not-working-properly-please-help/#findComment-667527 Share on other sites More sharing options...
.josh Posted October 16, 2008 Share Posted October 16, 2008 Yeah okay we get it, the switch isn't working. But again: With over 5000 posts, I would have thought you'd have realised that we need a touch more than 'not working' to help diagnose a problem. Quote Link to comment https://forums.phpfreaks.com/topic/128770-solved-switch-not-working-properly-please-help/#findComment-667549 Share on other sites More sharing options...
redarrow Posted October 16, 2008 Author Share Posted October 16, 2008 yes i agree i am sorry....... Quote Link to comment https://forums.phpfreaks.com/topic/128770-solved-switch-not-working-properly-please-help/#findComment-667553 Share on other sites More sharing options...
.josh Posted October 16, 2008 Share Posted October 16, 2008 LoL how about instead of agreeing and saying your sorry you actually tell us what the problem is? Is it not working because none of the cases are being triggered (nothing being echoed from any of them)? Is it not working because the wrong one is being triggered? Some kind of syntax error? Any error messages being displayed at all? Come on man... Quote Link to comment https://forums.phpfreaks.com/topic/128770-solved-switch-not-working-properly-please-help/#findComment-667573 Share on other sites More sharing options...
kenrbnsn Posted October 17, 2008 Share Posted October 17, 2008 I think your problem may be that you have an extra "}" before the switch statement. If you would indent properly, things like this can be avoided. I took the liberty of re-writing your code to get rid of the switch statement. My code uses arrays to hold the error messages and implode() to output them. <?php $err_msgs = array('Make sure you fill in all the form.','Make sure the name of the file is a .doc.','Sorry we have that file name!.'); $error = array(); if(isset($_POST['submit'])){ $new_doc=trim($_POST['new_doc']); $file_name=strtolower(strtoupper(trim($_POST['file_name']))); $cheek=$_POST['cheek']; $error=$_POST['error']; if( empty($new_doc) && empty($file_name) ){ $error[] = $err_msgs[0]; } $cheek=substr($file_name,-4); if($cheek !='.doc') { $error[] = $err_msgs[1]; } $x=glob("*.*"); if(in_array($file_name,$x)){ $error[] = $err_msgs[2]; } if(empty($error)){ $fh=fopen($file_name, 'w+'); fwrite($fh, $new_doc); fclose($fh); echo "<center>THANK YOU FILE CREATED AS A WORD DOCUMENT!</center>"; } else { $tmp = array(); $tmp[] = '<span style="text-align:center">Please try again, there was a problem:<br><br>'; $tmp[] = implode("<br>\n",$error) . '<br><br></span>'; echo implode("\n",$tmp); } } ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/128770-solved-switch-not-working-properly-please-help/#findComment-667606 Share on other sites More sharing options...
redarrow Posted October 18, 2008 Author Share Posted October 18, 2008 Nice work, But your code dosent order the errors correctly aswell, if you post the form with no values brings the error message of two arrays, error[0] and error[1] but only error[0] should be shown when there no values in the form.. i got the same problam with my oregianal code useing a switch..... any idears..... Quote Link to comment https://forums.phpfreaks.com/topic/128770-solved-switch-not-working-properly-please-help/#findComment-668749 Share on other sites More sharing options...
redarrow Posted October 18, 2008 Author Share Posted October 18, 2008 WAS ALL FOR FUN AND LEARNING PURPOSE..... SOLVED my code switch way to make a .word doc........ <?php if(isset($_POST['submit'])){ $new_doc=trim($_POST['new_doc']); $file_name=strtolower(strtoupper(trim($_POST['file_name']))); $cheek=$_POST['cheek']; $error=$_POST['error']; if(empty($_POST['new_doc']) || empty($_POST['file_name'])){ $error='FALSE'; }else{ $cheek=substr($file_name,-4); if($cheek !='.doc') { $error='FALSE2'; } } $x=glob("*.*"); if(in_array($file_name,$x)){ $error='FALSE3'; } if(!$error){ $fh=@fopen($file_name, 'w+'); @fwrite($fh, $new_doc); @fclose($fh); echo "<center>THANK YOU FILE CREATED AS A WORD DOCUMENT!</center>"; } } switch($error){ CASE "FALSE": echo "<center>PLEASE TRY AGIN THERE WAS A PROBLAM! <br><br> Make sure you fill in all the form. <br><br> </center>"; BREAK; CASE "FALSE2": echo "<center>PLEASE TRY AGIN THERE WAS A PROBLAM! <br><br> Make sure the name of the file is a .doc. <br><br> </center>"; BREAK; CASE "FALSE3": echo "<center>PLEASE TRY AGIN THERE WAS A PROBLAM! <br><br> Sorry we have that file name!. <br><br> </center>"; BREAK; } ?> <center> <form method="POST" action="<?php $_SERVER['PHP_SELF']; ?>"> <br> <br> Please name the file .doc <br> <br> <input type="text" name="file_name"> <br> <br> Please write your text <br> <br> <textarea name="new_doc" cols="30" rows="20"> </textarea> <br> <br> <input type="submit" name="submit" value="Export to Word"> <br><br> </form> </center> array way solved aswell to make a word.doc <?php $err_msgs = array('Make sure you fill in all the form.','Make sure the name of the file is a .doc.','Sorry we have that file name!.'); $error = array(); if(isset($_POST['submit'])){ $new_doc=trim($_POST['new_doc']); $file_name=strtolower(strtoupper(trim($_POST['file_name']))); $cheek=$_POST['cheek']; $error=$_POST['error']; if( empty($new_doc) && empty($file_name) ){ $error[] = $err_msgs[0]; }else{ $cheek=substr($file_name,-4); if($cheek !='.doc') { $error[] = $err_msgs[1]; } } $x=glob("*.*"); if(in_array($file_name,$x)){ $error[] = $err_msgs[2]; } if(empty($error)){ $fh=fopen($file_name, 'w+'); fwrite($fh, $new_doc); fclose($fh); echo "<center>THANK YOU FILE CREATED AS A WORD DOCUMENT!</center>"; } else { $tmp = array(); $tmp[] = '<span style="text-align:center">Please try again, there was a problem:<br><br>'; $tmp[] = implode("<br>\n",$error) . '<br><br></span>'; echo implode("\n",$tmp); } } ?> <center> <form method="POST" action="<?php $_SERVER['PHP_SELF']; ?>"> <br> <br> Please name the file .doc <br> <br> <input type="text" name="file_name"> <br> <br> Please write your text <br> <br> <textarea name="new_doc" cols="30" rows="20"> </textarea> <br> <br> <input type="submit" name="submit" value="Export to Word"> <br><br> </form> </center> Quote Link to comment https://forums.phpfreaks.com/topic/128770-solved-switch-not-working-properly-please-help/#findComment-668752 Share on other sites More sharing options...
redarrow Posted October 18, 2008 Author Share Posted October 18, 2008 little add on, to see the files .doc ur creating, and see what in the current files.... add it as is under the form....... <?php echo"<center> CURRENT FILES, PLEASE PRESS LINK TO SEE WHAT WRITTEN IN THEM!<BR><BR>"; $show=glob("*.doc*"); foreach($show as $show_files){ echo"<a href=' ".$_SERVER['PHP_SELF']."?cmd=$show_files'>$show_files</a><br>"; if($_GET['cmd']=="$show_files"){ $myFile = $show_files; $fh = fopen($myFile, 'r'); $theData = fread($fh, filesize($myFile)); fclose($fh); echo " <br>$myFile<br> $theData<br><br>"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/128770-solved-switch-not-working-properly-please-help/#findComment-668781 Share on other sites More sharing options...
redarrow Posted October 18, 2008 Author Share Posted October 18, 2008 Where can i find all the application types for the headers please in php.... Quote Link to comment https://forums.phpfreaks.com/topic/128770-solved-switch-not-working-properly-please-help/#findComment-668788 Share on other sites More sharing options...
GingerRobot Posted October 18, 2008 Share Posted October 18, 2008 Do you mean a list of mime types? http://www.iana.org/assignments/media-types/ Quote Link to comment https://forums.phpfreaks.com/topic/128770-solved-switch-not-working-properly-please-help/#findComment-668791 Share on other sites More sharing options...
redarrow Posted October 18, 2008 Author Share Posted October 18, 2008 How can i get the file to open in word on the fly with no download.... if the user press the relevent file if makes word open it .. I tried this with no joy........ <?php echo"<center>OPEN UP YOUR WORD DOC IN MS WORD NOW!</center>!<BR><BR>"; $show=glob("*.doc*"); foreach($show as $show_files){ echo"<a href=' ".$_SERVER['PHP_SELF']."?cmd=$show_files'>$show_files</a><br>"; if($_GET['cmd']=="$show_files"){ header("Content-Type: application/msword; charset=ISO-8859-1"); header("Content-Disposition: attachment; filename=\"$show_file\"" ); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/128770-solved-switch-not-working-properly-please-help/#findComment-668793 Share on other sites More sharing options...
redarrow Posted October 18, 2008 Author Share Posted October 18, 2008 this should work dosent.. error Fatal error: Uncaught exception 'com_exception' with message 'Failed to create COM object `word.application': Invalid syntax ' in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\simple_forum\word4.php:2 Stack trace: #0 C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\simple_forum\word4.php(2): com->com('word.applicatio...') #1 {main} thrown in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\sim\word4.php on line 2 <?php $word = new COM("word.application") or die ("Could not initialise MS Word object."); echo"<center>OPEN UP YOUR WORD DOC IN MS WORD NOW!</center>!<BR><BR>"; $show=glob("*.doc*"); foreach($show as $show_files){ echo"<a href=' ".$_SERVER['PHP_SELF']."?cmd=$show_files'>$show_files</a><br>"; if($_GET['cmd']=="$show_files"){ $word->Documents->Open(realpath("".$_SERVER['DOCUMENT_ROOT']."?$show_files")); echo $word; } } // Extract content. $content = (string) $word->ActiveDocument->Content; echo $content; $word->ActiveDocument->Close(false); $word->Quit(); $word = null; unset($word); ?> Quote Link to comment https://forums.phpfreaks.com/topic/128770-solved-switch-not-working-properly-please-help/#findComment-668800 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.