I've been using PHP for a little bit, but only doing basic tasks, and have gotten stuck while trying to build part of a knowledgebase.
While creating an article, you can upload screenshots - these need to be stored in a staging area until the article is saved, and I've got their information saved into the users session.
In POST upload:
...
$new_ss = array();
$new_ss['display_name'] = $ss_name;
$new_ss['server_path'] = "../uploads/"; /* outside of doc root */
$new_ss['server_path'] .= hash_file('md5', $ss_tmp_name) . "_" . $ss_name;
if ( @move_uploaded_file($ss_tmp_name, $new_ss['server_path']) )
{
$_SESSION['article']['screenshots'] .= $new_ss;
...
Then trying to display the upload to the user within the editing page:
if ( is_array($_SESSION['article']['screenshots']) && count($_SESSION['article']['screenshots']) > 0 )
{
echo "<table border=\"1\">\n";
foreach ( $_SESSION['article']['screenshots'] as $ss )
{
... display table of uploaded images ...
The trouble is, PHP isn't seeing $_SESSION['article']['screenshots'] as an array - and I can't see why.
After following the answer here: PHP foreach() with arrays within arrays? I tried quickly doing the following:
function print_array($key, $item) {
echo "$key -> $item\n";
}
...
{
$_SESSION['article']['screenshots'] .= $new_ss;
array_walk_recurisve($_SESSION['article']['screenshots'], 'print_array');
...
however I get the error "expects parameter 1 to be array, string given".
If I do an 'error_log($_SESSION['article']['screenshots']);' it just prints "Array" for however many images are uploaded, and print_r just printed '1' by itself.
Can someone shed some light please?