-1

I have a PHP script in which you can add text in some fields. The PHP script adds the text which are in the fields in 2 xml files. It is working good, but if the xml is getting too big (7000 lines is my xml), it can't write anymore.

I changed my php.ini into this

max_execution_time = 300     
max_input_time = 900    
;max_input_nesting_level = 64 ; Maximum input variable nesting level
memory_limit = 512M   

So is this problem caused by the php.ini or in PHP file. The script will only work when I delete a piece of xml code.

here is php

ini_set('default_charset', 'utf-8');
if(isset($_POST['post']) && $_POST['post']=='true')

{$file1Content = '<?xml version="1.0"?>
<channels>';
for($j=0; $j < $_POST['total1']; $j++)
{if(isset($_POST['checkbox1'.$j]) && $_POST['checkbox1'.$j]=="on")
{$file1Content .="
<channel>
<title>".$_POST['checkbox1'.$j.'_title']."</title>
<img>".$_POST['checkbox1'.$j.'_img']."</img>
<info>".$_POST['checkbox1'.$j.'_info']."</info>
<url>".$_POST['checkbox1'.$j.'_url']."</url>
</channel>";}}
$file1Content .= "</channels>";
$fileHandle = fopen($file1,"w");
fwrite ($fileHandle, $file1Content);
fclose ($fileHandle);


if (isset($_POST['post']) && $_POST['post']=="true" && $_POST['title']!='')
$fileContent = file_get_contents($file1);
$fileNewXml = "
<title>".$_POST['title']."</title>
<img>".$_POST['image']."</img>
<info>".$_POST['info']."</info>
<url>".$_POST['url']."</url>";  
 //Place elemnt in the right place
 $pos=$_POST['pos1'];   
$allTags=explode("<channel>",$fileContent,strlen($fileContent));
if(count($allTags)==1) //if file is empty
{$fileNewContent='<?xml version="1.0"?>
<channels>
<channel>"'.$fileNewXml.'</channel></channels>';}

    $fileHandle = fopen($file1,"w");

fwrite ($fileHandle, $fileNewContent);

fclose ($fileHandle);



<?php

                    $content= file_get_contents($file1);

                    $arr = simplexml_load_string($content);

                    $i=1;

                    foreach ($arr as $element)

                    { 

                        echo "<option value='$i'>$element->title</option>"; 

                        $i++;

                    }       

                ?>
Ar Megatox
  • 57
  • 1
  • 6

1 Answers1

0

to fix this just go to php.ini and add this

max_input_vars = 3000
Ar Megatox
  • 57
  • 1
  • 6
  • If the answer is a raise of [`max_input_vars`](https://php.net/manual/en/info.configuration.php#ini.max-input-vars), then the error message you might wanted to ask about was *"[PHP Warning: Unknown: Input variables exceeded 1000](http://stackoverflow.com/q/9673895/367456)"*. And as you picked 3000 as a value, you might relate to existing Q&A, namely [setting max_input_vars PHP.ini directive using ini_set](http://stackoverflow.com/q/9973555/367456) but I wonder a little about the number: Why 3000? – hakre Apr 26 '15 at 11:39