简体   繁体   中英

jquery-file-upload plugin - Changing the upload path

Im trying to change the path where my uploads are placed I want them to sit in a directory in the root called 'uploads'

I have changed the URL path successfully

'upload_url' => 'http://www.mydomain.co.uk/uploads/',

But when I try to change the directory upload path the code will not work and an internal server error message. I can't seem to find anything relevant in the logs.

'upload_dir' => '../../uploads/',

This is the original bit of code

'upload_dir' => dirname($_SERVER['SCRIPT_FILENAME']).'/files/',
'upload_url' => $this->getFullUrl().'/files/',

The path to the script is $_SERVER['ROOT']/server/php/index.php and the original files directory was within the /server/php directory. So I'm trying to go back two deep.

The weird thing is this works:

'large' => array(
'upload_dir' => '../../uploads/',
'upload_url' => 'http://www.mydomain.co.uk/uploads/',
'max_width' => 1920,
'max_height' => 1200,
'jpeg_quality' => 95
),
'thumbnail' => array(
'upload_dir' => '../../thumbs1/',
'upload_url' => 'http://www.mydomain.co.uk/thumbs1/',
'max_width' => 80,
'max_height' => 80
)

But as soon as I do the same to the main options it falls apart. Im at a loss!

Here is a similar question. The comments in the post mention that those options should accept parent folder paths such as ../folder .

Its answer isn't that the path wasn't working. Its something to do with the size of the directory! as its very large with thousands of images. So it seems the script falls apart with huge image directories. Will need to work a way around this :( Maybe get the script to check the database for conflicting filenames instead of searching through the directory as I think thats the issue.

Fixed, not sure if this was the best way round but it works!

I ditched this protected function get_file_objects() function

As that was scanning the directory and was not cool from a memory point of view if you have massive folders.

I then added some random unique numbers to the start of the 'trim file name' function

protected function trim_file_name($name, $type, $index) {
$realname = $name; 
 $realname = strtolower($realname);mt_srand((double)microtime()*3000000);
 $randvar =  mt_rand(3,30000000);
 settype($randvar,"string"); $file_name = trim(basename(stripslashes($randvar.$name)), ".\x00..\x20");

And thats it, so I have a unique filename without searching the directory

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM