Solved

PHP Array

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
hbo knew my windows software 4 63
How to make a good PHP + MySQL + JS pagination system? 3 35
Row insertion failed. Array 5 48
jQuery force form POST 7 51
A publishing tool, a Version Control System, or a Collaboration Platform! These can be some of the defining words for the two very famous web-hosting Git repositories: Bitbucket and Github. Git is widely used amongst the programmers and developers f…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

828 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