Skip to content
Advertisement

Is it possible to load an XML file using a variable name?

I know that to load a file we use

$xml = simplexml_load_file("file.xml") or die("Error");

But i want something like

$target_dir = "directory/";
$target_file = $target_dir. basename ($_FILES["XMLfile"]["name"]);
$xml = simplexml_load_file($target_dir/$_FILES["XMLfile"]) or die("Error");
print_r($ xml);

but it doesn’t work

Advertisement

Answer

I found it it’s

$xml=simplexml_load_file($target_dir.$_FILES["XMLfile"]["name"]) or die("Error");

not

$xml=simplexml_load_file($target_dir/$_FILES["XMLfile"]["name"]) or die("Error");
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement