1

I am trying to populate an array with a path to a file.

<?php
session_start(session_id());
$galleryID = $_SESSION['newGalleryId'];
    $path_pages = '../../../../data/gallery/' . $galleryID . '/images/album/';
?>

<?php
class UploadHandler
{
    protected $options;

    function __construct($options=null) {
        $this->options = array(
            'script_url' => $this->getFullUrl().'/',
            'upload_dir' => $path_pages,
            'upload_url' => $path_pages,
            'param_name' => 'files'
}
?>

I am using the jQuery-file-upload to upload files to a directory. If I hard code the $galleryID in it works fine, but when I try to plug in the $variable it doesn't work. Any ideas why the $galleryID is causing me issues.

Thanks

6
  • 3
    var_dump($galleryID) and what do you see? Is it the same value as the hard coded one? Commented Jun 14, 2012 at 18:22
  • also, why are you supplying a session id? try calling session_start() without session_id() Commented Jun 14, 2012 at 18:26
  • 1
    var_dump($path_pages) and what do you see? Commented Jun 14, 2012 at 18:26
  • @Bungdaddy - please post var_dump($_SESSION['newGalleryId']); Commented Jun 14, 2012 at 18:26
  • I have session id being called as this php is being called in a modal window with an existing session id Commented Jun 14, 2012 at 18:35

2 Answers 2

4

Try:

<?php
session_start();
$galleryID = $_SESSION['newGalleryId'];
$path_pages = '../../../../data/gallery/' . $galleryID . '/images/album/';
?>

Sounds like the $_SESSION is not starting. Adding session_start will instantiate the session and hopefully pull your variable.

Update

You should set your options like so:

<?php
session_start(session_id());
$galleryID = $_SESSION['newGalleryId'];
    $path_pages = '../../../../data/gallery/' . $galleryID . '/images/album/';

$options = array(
            'upload_dir' => $path_pages,
            'upload_url' => $path_pages,
            'param_name' => 'files');

$upload = new UploadHelper($options);
?>

<?php
class UploadHandler
{
    protected $options;

    function __construct($options=null) {
        $this->options = array(
            'script_url' => $this->getFullUrl().'/'
             );
}
?>

Your $path_pages does not have any visibility into the UploadHelper class. Since the class can handle options in the constructor, pass the options when instantiating the class.

Sign up to request clarification or add additional context in comments.

4 Comments

I should have shown that in my example, I do have session_start(session_id());
left out the $_SESSION in my example. Edited in example. I have the $galleryID pulling, when I add the $path_pages in the function it's not working. When I hard code in the function, works fine.
Ok, so you are setting options inside the UploadHelper. Don't. Updating answer.
I am sure knowing how to implement your code would work great. I couldn't get it to happen. I did however move the $galleryID = $_SESSION['newGalleryId']; into the __construct and it's working. Thanks for your help.
-1

As it is a pretty incomplete sample, I can only guess: You may have to reference to $path_pages using ether global $path_pages; or $GLOBALS['path_pages'].

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.