Jackie Jackie - 19 days ago 4x
Javascript Question

Dropzone js and Verot's upload, how to upload to dynamic folder?

I'm using Dropzone.js and Verot's class.upload.php to create a simple upload file.
I want to have images upload to folders dynamically from a $_GET[] variable.

Below is the code I have, but no matter what I do, all files get uploaded to "uploads" folder.


<?php include('includes/php/class.upload.php'); ?>

<form action="upload.php" class="dropzone"></form>


$filesFolder = 'uploads';

$targetDir = dirname(__FILE__).$ds.$filesFolder.$ds.$_GET['album'];
$targetDir = dirname(__FILE__).$ds.$filesFolder;


$handle = new upload($_FILES['file']);

if ($handle->uploaded) {
$handle->image_resize = true;
$handle->image_x = 960;
$handle->image_ratio_y = true;


So, if the url is index.php?album=rocks, images should get uploaded to "uploads/rocks". But, right now all gets uploaded to "uploads".

If I change the $filesFolder variable directly to "uploads/rocks" file uploads to the intended folder.

Am I doing something wrong? or is there a better way to achieve this besides using $_GET.


The issue with your code is the $_GET['album'] does not exist based on your current code, So the extended path never gets created. You must use a hidden input in your form for a GET request. But also be advised if your plan on using this code in on a live website or software please properly secure the data with validation and sanitization.

<form action = "upload.php" method="get" enctype="multipart/form-data">
    <input type="hidden" name="dir" value="album"/>
    <input type="submit"/>