Marcel Epp Posted February 22, 2016 Posted February 22, 2016 Hi, i need some help to create xml files from my upload form. For the form i used Soma's excellent example: https://gist.github.com/somatonic/5233338 i modified it. I only have an email field and the upload. I don't erase the files in my tmp folder. What i want is to create xml files with the same name. The same name that my files have. Example: photo1.png photo2.png photo1.xml photo2.xml .... i tried this code but i get stuck where i have to submit the entry from my email field. // remove extension from filename $withoutExt = preg_replace('/\\.[^.\\s]{3,4}$/', '', $files); // create xml for switch $doc = new DOMDocument('1.0'); $doc->formatOutput = true; $root = $doc->createElement('phpemail'); $root = $doc->appendChild($root); $email = $doc->createElement('email'); $email = $root->appendChild($email); $text = $doc->createTextNode($form_fields); $text = $email->appendChild($text); $doc->save($upload_path . $withoutExt . ".xml");
dragan Posted February 22, 2016 Posted February 22, 2016 $text = $doc->createTextNode($form_fields); $form_fields is an array: https://gist.github.com/somatonic/5233338#file-form-upload-php-L25 Depending on whether you limit your upload to just one file, or multiple files, you have to add some $form_fields foreach stuff to create one XML for each file... 1
Marcel Epp Posted February 22, 2016 Author Posted February 22, 2016 Hello dragan, thanks for your answer. It sound silly, but sometimes all i need is little help. You are right. I removed the extension and did a foreach on that array. This works for me: // create XML files for switch // remove extension from files $withoutExt = preg_replace('/\\.[^.\\s]{3,4}$/', '', $files); foreach($withoutExt as $withoutExt_string) { $doc = new DOMDocument('1.0'); // we want a nice output $doc->formatOutput = true; $root = $doc->createElement('phpemail'); $root = $doc->appendChild($root); $email = $doc->createElement('email'); $email = $root->appendChild($email); $text = $doc->createTextNode(($form_fields ["email"]["value"])); $text = $email->appendChild($text); $doc->save($upload_path . $withoutExt_string . ".xml"); } To get the email value i used var_dump to go trough the array. $text = $doc->createTextNode(($form_fields ["email"]["value"]));
Pravin Posted November 18, 2016 Posted November 18, 2016 @Marcel Epp so did you use the file-upload.php to upload the form details into xml file? and where do i have to invoke the create xml code snippet at ?
Marcel Epp Posted November 21, 2016 Author Posted November 21, 2016 @Pravin Hi Pravin, it's been a while since i played with processwire... My setup was a little bit confusing. I ended up having three files. As i look trough my files. When you have managed the upload, you probably have some sort of files array. In my files i used some part of wire upload i think. // RC: create temp path if it isn't there already if(!is_dir($upload_path)) { if(!wireMkdir($upload_path)) throw new WireException("No upload path!"); } // setup new wire upload $u = new WireUpload('file'); $u->setMaxFiles($max_files); $u->setMaxFileSize($max_upload_size); $u->setOverwrite($overwrite); $u->setDestinationPath($upload_path); $u->setValidExtensions($file_extensions); // start the upload of the files $files = $u->execute(); Now i had my "files" array. Then i put my xml code in. // create XML files for switch // remove extension from files $withoutExt = preg_replace('/\\.[^.\\s]{3,4}$/', '', $files); foreach($withoutExt as $withoutExt_string) { $doc = new DOMDocument('1.0'); // we want a nice output $doc->formatOutput = true; $root = $doc->createElement('phpemail'); $root = $doc->appendChild($root); $email = $doc->createElement('email'); $email = $root->appendChild($email); $text = $doc->createTextNode($newemail); $text = $email->appendChild($text); $doc->save($upload_path . $withoutExt_string . ".xml"); } hope it helps. 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now