Solved

PHP Array

Posted on 2007-11-28
3
235 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

Get Database Help Now w/ Support & Database Audit

Keeping your database environment tuned, optimized and high-performance is key to achieving business goals. If your database goes down, so does your business. Percona experts have a long history of helping enterprises ensure their databases are running smoothly.

Question has a verified solution.

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

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…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

751 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