Solved

PHP Array

Posted on 2007-11-28
3
227 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…
This video teaches users how to migrate an existing Wordpress website to a new domain.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now