alanl1 Posted July 1, 2013 Share Posted July 1, 2013 Hi Professionals. I have some code that puts a csv file into an array, this works great for lots of different files, with the expetion with one file that will not work. I think it may be a permissions problem. anyway here is my code, I have taken out all the javascript funtions to make it more readable. Is there any way the permissions can be changed, when I went and manually checked the file i tried to open it in notepad and it said access denied. I am not to good with windows but anyway I changed the permissions and was able to open it with notepad successfully, however it still looks like its not opening via my code. <?php $newname = $_GET['newname']; $filename = basename($newname,"/"); //basename function strips the "/" to retreive just filename from the Uploads folder... ?><form method='POST' name="myform" action="cleanse.php?filename=<?php echo htmlentities(urlencode($filename)); ?>" ><?php // Counter variable necessary for dynmaic drop down box on javascript client side function $counter = 1; echo "About to open file " .$filename; if (($handle = fopen($filename, "r")) !== FALSE) { $length = 1000; $delimiter = ","; $rows = 0; while ( ( $data = fgetcsv( $handle, $length, $delimiter ) ) !== FALSE ) { if( $rows == 0 ) { $num = count($data); echo "<table width=100% border=0>"; echo "<tr width=100% align=center><td colspan=4> </td></tr>"; echo "<tr width=100% align=center><td colspan=4 style=white-space:nowrap;width:100%;></td></tr>"; echo "<tr width=100%><td width=25%> </td><td width=20%> </td><td width=15%> </td><td width=40%> </td></tr>"; echo "<tr width=100%><td width=25% align=right> </td><td colspan=3>Selecting one to many allows for 3 columns, De-selecting one to many only allows the first set of columns</td></tr>"; echo "<tr width=100%><td width=25% align=right> </td><td colspan=3> </td></tr>"; echo "<tr width=100%><td width=25% align=right> </td><td width=20%>"; echo "<input type=checkbox id=cbox name=cbox value=unselected onclick=show_hide(this.checked);>One to many</td>"; //One to many checkbox echo "<td width=15%> </td><td width=40%> </td></tr>"; echo "<tr width=100%><td width=25%> </td><td width=20%> </td><td width=15%> </td><td width=40%> </td></tr></table>"; for ($c=0; $c < $num; $c++) { echo "<table width=100% border=0><tr width=25% align=right><td>"; //Second array element populates the dropdown and calculates the number of columns from spreadsheet for ($d=0; $d < $num; $d++) { //echo "<option value='" .$data[$d]."'>" .$data[$d]."</option>"; } ?><input type="text" name="<?php echo "textbox[" .$c ."]" ?>" id="<?php echo "textbox[" .$data[$c]."]" ?>" value="<?php echo $data[$c] ?>" readonly style="background-color:White; color:Black;"> <?php echo "<td width=20% align=left>"; ?> <---- Matches to -----> <select name="<?php echo "dropdown[" .$c."]"?>" onchange="fillSelect(this,categories[this.value],'<?php echo "dropdown" .$counter++ ?>')"><?php echo "<option selected>Please Choose</option>"; echo "<option value='Software Manufacturer" .$c. "'>Software Manufacturer</option>"; echo "<option value='Product Name" .$c. "'>Product Name</option>"; echo "<option value='Product Version" .$c. "'>Product Version</option>"; echo "<option value='Keep Existing'>Keep Existing</option>"; echo "<option value='Ignore'>Ignore</option>"; ?></select><?php echo "</td><td width=15% align=left>"; ?> <select name="<?php echo "secondDD[" .$c ."]" ?>" id="<?php echo "secondDD[" .$c."]" ?>" style="display:none;" ><?php echo "<option selected>Please Choose</option>"; echo "<option value='Software Manufacturer2" .$c. "'>Software Manufacturer</option>"; echo "<option value='Product Name2" .$c. "'>Product Name</option>"; echo "<option value='Product Version2" .$c. "'>Product Version</option>"; echo "<option value='Keep Existing2" .$c. "'>Keep Existing</option>"; echo "<option value='Ignore2" .$c. "'>Ignore</option>"; ?></select><?php echo "</td><td width=40% align=left>"; ?> <select name="<?php echo "thirdDD[" .$c ."]"?>" id="<?php echo "thirdDD[" .$c."]" ?>" style="display:none;"><?php echo "<option selected>Please Choose</option>"; echo "<option value='Software Manufacturer3" .$c. "'>Software Manufacturer</option>"; echo "<option value='Product Name3" .$c. "'>Product Name</option>"; echo "<option value='Product Version3" .$c. "'>Product Version</option>"; echo "<option value='Keep Existing3" .$c. "'>Keep Existing</option>"; echo "<option value='Ignore3" .$c. "'>Ignore</option>"; ?></select><?php echo "</td></tr></table>"; } } $rows++; // ADDED } fclose($handle); } ?><br /><table width="100%" border="0"> <tr> <td width=25% align=center> </td> <td width=25% align=center> </td> <td width=25% align=left><input name="Clean" align="center" type="submit" value="Load"/></td> <td width=25% align=center> </td> </tr> </table> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/279768-csv-to-array/ 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.