473,378 Members | 1,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

fill $_FILES argument from XML parser

I've a function asking for a $_FILES argument:

function insertarticle($particle,......,$pUserID,$pOptions, $files){
in this function I do add the record and then save the files in a
subdirectory specific on some datas.

This function is used by my "insert" form, letting the user to select images
files to upload with <FILE> html tag.
The files to upload are then passed to the $files like this:
insertarticle(1884,......,4,$Options,$_FILES);

for mantainance purpose, I avoid as much as possible to have the same code
in 2 different pages. Also, using actually this function to add a record in
the database (quite complex code) and saving files from a form, and using
the same function to add records from an XML parser, I can't send images
files to the function.

My parser can save the images files on the server's directory, but how to
pass $files parameters in order to save those files ? It's there any way to
take the string containing the base64 image code (I do actually save it
locally) and put it in a $_FILES array for passing it to the function ?

thanks for help.

Bob
Jul 17 '05 #1
1 2610
Bob Bedford wrote:
My parser can save the images files on the server's directory, but
how to pass $files parameters in order to save those files ? It's
there any way to take the string containing the base64 image code (I
do actually save it locally) and put it in a $_FILES array for
passing it to the function ?


You will have to convert each $_FILES array to a format that can be parsed
by the XML parsing function.

When the code of the XML parsing function equals the one in your earlier
post, the expected array probably looks like this:

Array (
Array(
[NUM] => 2,
[PICTURES] => Array(
Array(
"PIC",
"base64 encoded data"
),
Array(
"PIC",
"base64 encoded data"
)
)
)
)

The $_FILES array would contain something like the following:

Array
(
[uploadfieldname] => Array
(
[name] => test.png
[type] => image/x-png
[tmp_name] => /tmp/php3D.tmp
[error] => 0
[size] => 30230
)

)

Now, to convert the arrays, you could use the following code:

<?php
if (isset($_FILES)) {
$data = array();
foreach ($_FILES as $uploaded) {
if (!$uploaded["error"]) {
$pic = array(
"PIC",
chunk_split(
base64_encode(
file_get_contents(
$uploaded["tmp_name"]
)
)
)
);

if (!isset($data["PICTURES"])) {
$data["PICTURES"] = array($pic);
} else {
$data["PICTURES"][] = $pic;
}

if (!isset($data["NUM"])) {
$data["NUM"] = 1;
} else {
$data["NUM"]++;
}
}
}
}
?>

After this you can call the XML parser function with $data as the argument.
However, as you will have noticed, the image data get base64_encoded.

It would be better to introduce a flag in the PICTURES array of $data to
indicate that the data is base64 encoded...
HTH;
JW

Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Harry | last post by:
I need to read resumes from PDF, DOC, RTF and text file and fill in the relevent fields in database. My application is based on dotnetnuke (asp.net) can anyone help me if something is available.
3
by: Himanshu Garg | last post by:
Hello, I am trying to pinpoint an apparent bug in HTML::Parser. The encoding of the text seems to change incorrectly if the locale isn't set properly. However Parser.pm in the directory...
4
by: annoyingmouse2002 | last post by:
Hi there, sorry if this a long post but I'm really just starting out. I've been using MSXML to parse an OWL but would like to use a different solution. Basically it reads the OWL (Based on XML)...
4
by: webdev | last post by:
lo all, some of the questions i'll ask below have most certainly been discussed already, i just hope someone's kind enough to answer them again to help me out.. so i started a python 2.3...
9
by: Ritesh Raj Sarraf | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, I'm using optparse module to parse all options and arguments. My program uses mostly "option arguments" hence my len(args) value is always...
30
by: Raymond Hettinger | last post by:
Proposal -------- I am gathering data to evaluate a request for an alternate version of itertools.izip() with a None fill-in feature like that for the built-in map() function: >>> map(None,...
8
by: Andrew Robert | last post by:
Hi Everyone. I tried the following to get input into optionparser from either a file or command line. The code below detects the passed file argument and prints the file contents but the...
3
by: Jmc | last post by:
Hi I'm trying to build a log viewer, its going to be part of a contentmanagement system and needs some extra features that commersial logviewers donīt have. The log files (IIS log) are...
6
by: 31337one | last post by:
Hello all, I was wondering if there is a C/C++ command line parser that works for linux AND windows. . Anyways, the ideal parser im looking for should be able to support multiple arguments...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.