Solved

PHP Array

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Creating and Managing Databases with phpMyAdmin in cPanel.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

770 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