Jump to content

Csv to array


alanl1

Recommended Posts

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>&nbsp</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%>&nbsp</td><td width=20%>&nbsp</td><td width=15%> </td><td width=40%> </td></tr>";
   echo "<tr width=100%><td width=25% align=right>&nbsp</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>&nbsp</td><td colspan=3>&nbsp</td></tr>";
   echo "<tr width=100%><td width=25% align=right>&nbsp</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%>&nbsp</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>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.