Advertisement:

Author Topic: Several installations sharing same database and images folder [Solved]  (Read 10124 times)

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: Upload path
« Reply #15 on: November 16, 2015, 09:43:17 pm »
Mmmzzz and no errors in logfile..... maybe in other logfile using your cpanel?

Image upload is usually two-step using ajax upload, do images when posting a new add appear in step 1? Ie. you add images and they appear as small images or is there no upload from the start so not even smaller images?

Yes, after I select them they upload normally and display under image uploader. If I inspect them, they are placed inside subdomain (the page I'm using) temp folder.

p206ab

  • Sr. Member
  • ****
  • Posts: 343
Re: Upload path
« Reply #16 on: November 16, 2015, 10:04:40 pm »
Mmmzzz and no errors in logfile..... maybe in other logfile using your cpanel?

Image upload is usually two-step using ajax upload, do images when posting a new add appear in step 1? Ie. you add images and they appear as small images or is there no upload from the start so not even smaller images?

Yes, after I select them they upload normally and display under image uploader. If I inspect them, they are placed inside subdomain (the page I'm using) temp folder.

Nothing  :'(
I'm starting to lose my patience with this problem. I know Osclass originally isn't meant to be used like this, but I managed to solve every problem with only this one left....Temporary solution was to redirect them to main domain after clicking post new ad button. But I really want to solve this as it may discourage users to post when they are redirected for example from german subdomain to main domain in english.
Thanks for all the help SmaRTeY and teseo, will try to go from the start on another subdomain to see if I only made a mistake somewhere and check all options. If I find something, I will surely write it here for future reference.
And if by any chance you figure out any other option, please let me know ;)
Thanks again for your time.

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: Upload path
« Reply #17 on: November 16, 2015, 10:16:11 pm »
I can see your frustration....sorry to see but I do not know what else it could be.
It is like teseo mentioned, having that path corrected you would expect it to work....

Good luck!

p206ab

  • Sr. Member
  • ****
  • Posts: 343
Re: Upload path
« Reply #18 on: November 19, 2015, 02:09:20 pm »
Thanks.

Quick update on this:
I managed to edit, so

row 1485 in item.form.class.php
Code: [Select]
$(li).append('<div class="ajax_preview_img"><img src="<?php echo osc_base_url(); ?>oc-content/uploads/temp/'+responseJSON.uploadName+'" alt="' + responseJSON.uploadName + '"></div>');where I edited
<img src="<?php echo osc_base_url(); ?>oc-content/uploads/temp/
to
<img src="http://maindomain.com/oc-content/uploads/temp/

so now post/edit ad form requests for temp photos from main domain's temp folder.
Now I only need to set it to upload there.

I found this in the same file on row 1430:
Code: [Select]
$('#restricted-fine-uploader').fineUploader({
                        request: {
                            endpoint: '<?php echo osc_base_url(true)."?page=ajax&action=ajax_upload"?>'

So could this be the action which triggers upload function and if I replace osc_base_url like above with main domain, it should result in the same action, therefore upload into domain's upload folder?

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Upload path
« Reply #19 on: November 20, 2015, 12:49:45 am »
Hi again,

@p206ab, frankly I don't think you are on the right track. ??? Your problem isn't in the Ajax part of the process, but in moving the generated final images to the /uploads folder of main domain root folder.

I believe this problem can be resolved this way:

1.- Once normally generated all the variants (normal, preview, thumbnail) in subdomain uploads folder by the core script, they should be moved to domain uploads folder. This can be achieved outside the core ("uploaded_file" hook).

2.- An the second part is to always look for all images inside domain uploads folder. For this there is a filter "resource_path".

Tomorrow I'll provide the needed code.

Regards

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Upload path
« Reply #20 on: November 20, 2015, 06:36:17 pm »
***CORRECTED AGAIN***

This should work provided all your Osclass installation are in the same server.

First make a backup of the files you have been modifying for this and restore the original ones.

Add this at the very bottom of your theme functions.php (on both installations):
Notes:
1.- Take care not to leave blank lines after this.
2.- If your theme functions.php doesn't end with ?> skip first line of my code.

Code: [Select]
<?php
function cust_move_images_to_main_domain($resource) {

    
$mainPath '/path-to-your-main-domain-root-folder/'// Change to your main domain installation root folder

    
if (osc_base_path() != $mainPath) {
        
$currentFolder osc_base_path().$resource['s_path'];

        if(!
is_dir($mainPath.$resource['s_path'])) {
            if (!
mkdir($mainPath.$resource['s_path'], 0755true)) {
                return; 
// PATH CAN NOT BE CREATED
            
}
        }

        
rename($currentFolder.$resource['pk_i_id'].'.'.$resource['s_extension'], $mainPath.$resource['s_path'].$resource['pk_i_id'].'.'.$resource['s_extension']);
        
rename($currentFolder.$resource['pk_i_id'].'_preview.'.$resource['s_extension'], $mainPath.$resource['s_path'].$resource['pk_i_id'].'_preview.'.$resource['s_extension']);
        
rename($currentFolder.$resource['pk_i_id'].'_thumbnail.'.$resource['s_extension'], $mainPath.$resource['s_path'].$resource['pk_i_id'].'_thumbnail.'.$resource['s_extension']);

        if( 
osc_keep_original_image() ) {
            
rename($currentFolder.$resource['pk_i_id'].'_original.'.$resource['s_extension'], $mainPath.$resource['s_path'].$resource['pk_i_id'].'_original.'.$resource['s_extension']);
        }
    }
}

osc_add_hook('uploaded_file''cust_move_images_to_main_domain');

function 
cust_change_resource_path($url) {

    
$mainUrl 'http://mydomain.com/'// Change to your main domain URL
    
return str_replace(osc_base_url(), $mainUrl$url);
}

osc_add_filter('resource_path''cust_change_resource_path');

function 
cust_delete_resource($resource) {
    
$mainPath '/path-to-your-main-domain-root-folder/'// Change to your main domain installation root folder

    
if (osc_base_path() != $mainPath) {
        @
unlink($mainPath $resource['s_path'] . $resource['pk_i_id'] . "." $resource['s_extension']);
        @
unlink($mainPath $resource['s_path'] . $resource['pk_i_id'] . "_original." $resource['s_extension']);
        @
unlink($mainPath $resource['s_path'] . $resource['pk_i_id'] . "_thumbnail." $resource['s_extension']);
        @
unlink($mainPath $resource['s_path'] . $resource['pk_i_id'] . "_preview." $resource['s_extension']);
    }
}
 
osc_add_hook('delete_resource''cust_delete_resource');
?>


Change path and URL in these lines:

Code: [Select]
$mainPath = '/path-to-your-main-domain-root-folder/'; // Change to your main domain installation root folder(2 occurrences)

Code: [Select]
$mainUrl = 'http://mydomain.com/'; // Change to your main domain URL
Regards
« Last Edit: May 02, 2018, 01:56:19 pm by teseo »

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: Upload path
« Reply #21 on: November 20, 2015, 10:12:25 pm »
Great workout teseo!

I can see what the functions do but I do not understand what that filter hook exactly does and why "always look for all images inside domain uploads folder" is needed? I thought adding the 'move' of subdomain uploads would be sufficient :)

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Upload path
« Reply #22 on: November 20, 2015, 10:28:49 pm »
Hi Eric,

That filter is mainly used on this function of hItems.php:

Code: [Select]
    function osc_resource_path() {
        return (string) osc_apply_filter('resource_path', osc_base_url().osc_resource_field("s_path"));
    }

Normally images are retrieved using this helper. When you are in a subdomain page that returns something like:

Code: [Select]
http://subdomain.domain.com/oc-content/uploads/4/
The subdomain installation expects to find the images in its own folders, but previously we have moved those images to main domain installation, so here we need to direct the script to main domain URL.

Code: [Select]
http://domain.com/oc-content/uploads/4/
Regards

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: Upload path
« Reply #23 on: November 20, 2015, 10:32:57 pm »
Aaaaahhhh it is 'order' related more or less, thank you! :)

p206ab

  • Sr. Member
  • ****
  • Posts: 343
Re: Upload path
« Reply #24 on: November 21, 2015, 09:39:49 pm »
Whoa teseo, amazing work! Thank you so much! Where do you accept donations? :) 8) 8)

Although I haven't manage to confirm it's working for me, I edited functions as told and now I finally have something in my error log: "PHP Warning:  mkdir(): open_basedir restriction in effect."  ..so basically it was always permission problem and I should edit that, but since my host does not allow config, I'll have to wait until monday to let them make changes.

But I'm sure this will finally solve my problems ;)

p206ab

  • Sr. Member
  • ****
  • Posts: 343
Re: Upload path [SOLVED]
« Reply #25 on: November 24, 2015, 12:10:29 am »
IT WOOOOOORKS!!!!  :D :D

sorry for caps but I'm so happy :)
Thank you teseo!!!

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Upload path [SOLVED]
« Reply #26 on: November 24, 2015, 01:09:23 pm »
Glad you got it working, you're welcome. :)

Would you mind changing the title of this thread to something more descriptive such as "Several installations sharing same database and images folder [Solved]"? Thanks.

Regards

itcafeonline

  • Full Member
  • ***
  • Posts: 245
Re: Upload path [SOLVED]
« Reply #27 on: November 24, 2015, 03:22:32 pm »
teseo, can this be extended  to have two osclass installations in different folders using the same set of users (within the same database? Authenticate at one, and its valid for the other?

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Upload path [SOLVED]
« Reply #28 on: November 24, 2015, 06:28:18 pm »
I think storing sessions in a common folder should work (at least it works on my server).

1.- Create common folder /[path-to-your-main.installation-root-folder]/oc-content/uploads/sessions. Make sure it has the same owner as the rest of folders in /uploads.

2.- Add this line to each of your config.php, just above the last ?>

Code: [Select]
session_save_path ( '/[path-to-your-main.installation-root-folder]/oc-content/uploads/sessions/' );
Make sure you are logged-off in any installation before trying in a browser.

Regards

Mrbee

  • Newbie
  • *
  • Posts: 3
Re: Several installations sharing same database and images folder [Solved]
« Reply #29 on: April 13, 2016, 11:39:35 pm »
Hello Teseo,
I need help in this area
Here are my unique issues
1. I want to create two websites with one database. Same users, same listings, same pictures, different themes and slightly different domains.
2. Auto browser detect and redirection (in this case opera mini browser only)
3. I don't have any coding experience

I really do need urgent help