0

Long story short, I've been at this for quite a bit. I am teaching myself PHP, so please bear with any ignorance and I will happily clarify any and everything.

I'm using Blueimp's Jquery File Uploader and I'm having trouble having the uploader insert the uploaded files into the appropriate users' folder which I have set to be created automatically at registration. The JFU's native user directory ability does not work for me because all uploads are placed into the same session folder, a string of seemingly miscellaneous alphanumeric characters which I'm assuming is being read as the randomized session ID. So what I am trying to do is change the session to read as the logged-in username, and use that as its ID. I've scoured the internet and found various resources, but nothing has yet worked for me. Everything gets uploaded to the parent /uploads/ folder, but not the username-specific subfolders.

Previous post:

PHP Jquery File Upload // Username/Session Directories

(Some) Sources:

-How to get/set session_id() or should it be generated automatically?

-Jquery File Upload change session id

Using the advice given on my previous post, I still encounter the "Error SyntaxError: Unexpected token <" error, which I'm assuming means that the $username variable is failing to be defined/passed through.

The current login/session process is set at login, persists through pages, and exists as $loggedInUser->username (prints logged-in username on pages when called) and the session is read as $_SESSION['user_name']. I have tried applying every mix and match I can think of to the various sources I have found, and nothing seems to read the variable and insert the files into the appropriate user folders. Is there a way to tell the script to either read the session or read from database as the username, then upload into that username's folder?

My current code is as follows:

index.php

error_reporting(E_ALL | E_STRICT);
require('UploadHandler.php');
$upload_handler = new UploadHandler($username);

UploadHandler.php

function __construct($username, $options = null, $initialize = true, $error_messages = null) {
    $this->response = array();
    $this->options = array(
        'script_url' => $this->get_full_url().'/'.basename($this->get_server_var('SCRIPT_NAME')),
        'upload_dir' => dirname($this->get_server_var('SCRIPT_FILENAME')).'/../../uploads/'.$username.'/',
        'upload_url' => $this->get_full_url().'/../../uploads/'.$username.'/',
        'user_dirs' => false,
        'mkdir_mode' => 0755,
        'param_name' => 'files',

Thanks in advance for any and all help.

Community
  • 1
  • 1
  • is it whole code? if Yes so where You're starting session? session_start(); $username = $_SESSION['user_name']; require('UploadHandler.php'); – num8er Jul 18 '15 at 15:19
  • This is a complex utility, but basically you need to subclass the `UploadHandler` and override the standard method funtionality to achieve what you are tring to do. If you are not up on OOP you will get very lost very quickly. – RiggsFolly Jul 18 '15 at 15:25
  • @num8er At the head of my pages, I have require calls, one being config.php which is what reads the user settings and session calls. -- session_start(); if(isset($_SESSION["user_name"]) && is_object($_SESSION["user_name"])) { $loggedInUser = $_SESSION["user_name"]; } – I tried adding your comment to my index.php file, but no progress. – wobblybeard Jul 18 '15 at 16:07
  • @RiggsFolly I got very lost. Very quickly. – wobblybeard Jul 18 '15 at 16:07
  • Use: global $loggedInUser; to get variable from global scope. – num8er Jul 18 '15 at 16:09
  • @num8er Where do I input that code? – wobblybeard Jul 18 '15 at 16:39
  • Before require('UploadHandler.php'); – num8er Jul 18 '15 at 16:40
  • @num8er The $loggedInUser variable is still failing to be defined. I'm trying to keep up but I'm afraid that I'm failing to see the forest for the trees. `error_reporting(E_ALL | E_STRICT); global $loggedInUser; require('UploadHandler.php'); $upload_handler = new UploadHandler($loggedInUser);` – wobblybeard Jul 18 '15 at 16:46
  • Include config.php before global – num8er Jul 18 '15 at 16:47

0 Answers0