문제

So, I have been trying to figure this out for the past three hours, and I feel like I am nowhere close to getting it ... . Any help would be appreciated.

I have been able to set the jQuery File Uploader to save the uploaded images in a dynamic path/url. All seems to work, and the files are uploaded in the right places and show up on frontend. But, once reloaded the page, there is no sign of them. Obviously, it's path/directory url error. I just can't figure out what!

Here is my HTML file on http://127.0.0.1/local/platform/backend/page-edit.php

<form id="fileupload" method="POST" enctype="multipart/form-data">
   ...
   <input type="hidden" name="path" value="products"><!-- Setting the directory to save the img -->
   ...
</form>

JFU's PHP files UploadHandler.php and index.php are under http://127.0.0.1/local/platform/uploads/ index.php:

$options = array('upload_dir'=>$_POST['path'].'/'.date("Y").'/'.date("n").'/', 'upload_url'=>'../uploads/'.$_POST['path'].'/'.date("Y").'/'.date("n").'/');
error_reporting(E_ALL | E_STRICT);
require('UploadHandler.php');
$upload_handler = new UploadHandler($options);

main.js under http://127.0.0.1/local/platform/backend/plugins/jQuery-File-Upload-9.5.7/js/

$(function () {
'use strict';
$('#fileupload').fileupload({
    // Uncomment the following to send cross-domain cookies:
    //xhrFields: {withCredentials: true},
    url: '../uploads/'
});
...
});

As I said, the files upload and appear right. But when I refresh the page, they no longer appear in the table ... .

도움이 되었습니까?

해결책

Found the solution!

Basically, I am assigning the values I want as JS variables in the footer. I, then, use the variables that have the data I need on main.js like this:

$('#fileupload').fileupload({
   url: '.../uploads/index.php?page_type=' + THE_VARIABLE
});

Now, the data is passed to the index.php file under my uploads directory. So, I get the query string and send it to the UploadHandler.php:

parse_str($_SERVER['QUERY_STRING'], $query_string);
$options('upload_dir'=>$query_string['page_type'], 'upload_url'=>'../uploads/'.$query_string['page_type']);
...
$upload_handler = new UploadHandler($potions);

Boom! Works like a charm!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top