Solved

PHP Array

Posted on 2007-11-28
3
236 Views
Last Modified: 2008-02-01
Goal: To retrieve the Name for each FID.

Question: What do I have to do to print each name in the array?

Note: Please use the example to illustrate your idea.  

<?php
require 'HTTP/Upload.php';
//$lang = "en";
$upload = new HTTP_Upload("en");
$files = $upload->getFiles();
$_SESSION['path'] = "../uploads/";
foreach($files as $file){
    if (PEAR::isError($file)) {
        echo $file->getMessage();
    }
    if ($file->isValid()) {
        $file->setName("uniq");
        $dest_name = $file->moveTo("../uploads/");
        if (PEAR::isError($dest_name)) {
            echo $dest_name->getMessage();
        }
        $real = $file->getProp("real");
        $name = $file->getProp("name");
    } elseif ($file->isMissing()) {
        //echo "No file was provided.";
        break;
    } elseif ($file->isError()) {
        echo $file->errorMsg();
    }
    if (!empty($real)) {
    	if (isset($_SESSION)){
    	    $fid = insert_files($name, $real);
    	    $_SESSION['file'][$fid] = array('fid' => $fid, 'name' => $name, 'real' => $real);
            //echo "$fid";
            echo "<br />";
            //print_r($fid);
            //print_r($_SESSION['file'][$fid]);
            echo "<br />";
       	}
    }
}
?>
<?php 
echo "<br />";
print_r($_SESSION);
 
//What do I have to do to print each name in the array?
//File Name: new.jpg
//<img src="../uploads/28418474d9bfdcc87b.jpg" />
 
echo "<br />";
 
/*print_r($_SESSION);
Array ( [date] => 1969 12 31 19:00:00 [views] => 1 [path] => ../uploads/ [file] => Array ( [64] => Array ( [fid] => 64 [name] => 28418474d9bfdcc87b.jpg [real] => new.jpg ) [65] => Array ( [fid] => 65 [name] => 20792474d9bfde19ca.mov [real] => ref.mov ) [66] => Array ( [fid] => 66 [name] => 10480474d9bfdf1d62.mov [real] => ref.mov ) ) ) 
*/

Open in new window

0
Comment
Question by:taynet29
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
3 Comments
 
LVL 20

Accepted Solution

by:
steelseth12 earned 500 total points
ID: 20367025
Where you have print_r($_SESSION);

use

foreach($_SESSION['file'] as $key=>$value) {


      print "FID = ".$key."<br>";
      print "Name = ".$value["name"];
      
      print "<hr>";



}
0
 
LVL 20

Assisted Solution

by:steelseth12
steelseth12 earned 500 total points
ID: 20367040
if you are only interested in the name simply do

foreach($_SESSION['file'] as $value) {

      print "Name = ".$value["name"]."<br>";
      
}
0
 
LVL 20

Assisted Solution

by:steelseth12
steelseth12 earned 500 total points
ID: 20367053
For more information on foreach have a look at

http://www.php.net/manual/en/control-structures.foreach.php

For more information on array have a look at

http://www.php.net/manual/en/language.types.array.php
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question