Advertisement:

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

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Upload path [SOLVED]
« Reply #30 on: October 02, 2017, 10:23:45 pm »
IT WOOOOOORKS!!!!  :D :D

sorry for caps but I'm so happy :)
Thank you teseo!!!
Hi,
When i submit a item with my second osclass, it doesn't save photo in main osclass folder, why? I want to save both photos in main osclass.
First osclass is installed in root of host. And in root i have a folder (second) and installed second osclass.
For second osclass i don't know what to put for $mainPath
Please tell me what to put $mainPath for my second osclass. Thanks
$mainPath = ?
$mainUrl = www.mysite.com
« Last Edit: October 02, 2017, 10:25:31 pm by Sophia_OS »

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Upload path
« Reply #31 on: October 02, 2017, 10:30:53 pm »
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 $mainUrl.osc_resource_field("s_path");
}

osc_add_filter('resource_path''cust_change_resource_path');
?>


Change path and URL in these two lines:

Code: [Select]
$mainPath = '/path-to-your-main-domain-root-folder/'; // Change to your main domain installation root folder
Code: [Select]
$mainUrl = 'http://mydomain.com/'; // Change to your main domain URL
Regards

Hi teseo,

I don't know what to put $mainPath for my second osclass.

$mainPath = ?
$mainUrl = 'http://mysite.com/'; //

My First osclass is installed in root of host. And in root i have a folder (second) and installed second osclass.
« Last Edit: October 02, 2017, 10:33:05 pm by Sophia_OS »

Liath

  • issues
  • Hero Member
  • *
  • Posts: 1346
  • </html> the end is always near
Re: Several installations sharing same database and images folder [Solved]
« Reply #32 on: October 02, 2017, 10:32:47 pm »
usually your domain root path is something like this but it depends on the system where your page is running


/var/www/vhosts/yourdomain/httpdocs/


you could take a look in your phpinfo to find out the correct path

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Several installations sharing same database and images folder [Solved]
« Reply #33 on: October 02, 2017, 10:34:47 pm »
usually your domain root path is something like this but it depends on the system where your page is running


/var/www/vhosts/yourdomain/httpdocs/


you could take a look in your phpinfo to find out the correct path

Thank you, let me take look at php.ini

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Several installations sharing same database and images folder [Solved]
« Reply #34 on: October 02, 2017, 10:38:45 pm »
usually your domain root path is something like this but it depends on the system where your page is running


/var/www/vhosts/yourdomain/httpdocs/


you could take a look in your phpinfo to find out the correct path

Should i have to put the same $mainPath for both functions.php ? My first osclass is in root, and second one is in "second" folder in root.

Liath

  • issues
  • Hero Member
  • *
  • Posts: 1346
  • </html> the end is always near
Re: Several installations sharing same database and images folder [Solved]
« Reply #35 on: October 02, 2017, 10:42:04 pm »
maybe you will find it there, if not
  • create a new file in your domain root dir (e.g. info.php)
  • add following code to this file
  • open this file in your browser (http://yourdoma.in/info.php)
  • search there for $_SERVER['DOCUMENT_ROOT']
content for info.php
Code: [Select]
<?php echo phpinfo(); ?>



edit:
Should i have to put the same $mainPath for both functions.php ? My first osclass is in root, and second one is in "second" folder in root.
should be enough to add this to your second installation
« Last Edit: October 02, 2017, 10:43:35 pm by Liath »

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Several installations sharing same database and images folder [Solved]
« Reply #36 on: October 02, 2017, 11:08:44 pm »
maybe you will find it there, if not
  • create a new file in your domain root dir (e.g. info.php)
  • add following code to this file
  • open this file in your browser (http://yourdoma.in/info.php)
  • search there for $_SERVER['DOCUMENT_ROOT']
content for info.php
Code: [Select]
<?php echo phpinfo(); ?>



edit:
Should i have to put the same $mainPath for both functions.php ? My first osclass is in root, and second one is in "second" folder in root.
should be enough to add this to your second installation

Thanks Liath, i thought i have to install for both, because teseo's note is to put for all installation.
i coudnt find path in my php.ini,
let me test in localhost (wamp) first, what is path for wamp localhost?

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Several installations sharing same database and images folder [Solved]
« Reply #37 on: October 02, 2017, 11:12:20 pm »
i coudnt find $_SERVER['DOCUMENT_ROOT'] in php.ini in in both server and localhost

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Several installations sharing same database and images folder [Solved]
« Reply #38 on: October 02, 2017, 11:15:47 pm »
i think i found it,
localhost was this:
_SERVER["DOCUMENT_ROOT"]   C:/wamp/www
let me test this and see it works or not

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Several installations sharing same database and images folder [Solved]
« Reply #39 on: October 02, 2017, 11:26:47 pm »
it saves photos in second osclass upload folder: why?  ???
C:\wamp\www\second\oc-content\uploads\1

but it supposed to save here:
C:\wamp\www\oc-content\uploads\1

please take a look at code:
Code: [Select]
<?php
function cust_move_images_to_main_domain($resource) {

    
$mainPath '/C:/wamp/www/'// 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://localhost/'// Change to your main domain URL
    
return $mainUrl.osc_resource_field("s_path");
}

osc_add_filter('resource_path''cust_change_resource_path');
?>


Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Several installations sharing same database and images folder [Solved]
« Reply #40 on: October 03, 2017, 12:04:19 am »
 i think in this code, "$resource" gets the url of image to save in second osclass not main osclass
$currentFolder = osc_base_path().$resource['s_path'];

Liath

  • issues
  • Hero Member
  • *
  • Posts: 1346
  • </html> the end is always near
Re: Several installations sharing same database and images folder [Solved]
« Reply #41 on: October 03, 2017, 12:08:25 am »
should be enough to add this to your second installation

Thanks Liath, i thought i have to install for both, because teseo's note is to put for all installation.

it saves photos in second osclass upload folder: why?  ???

then you should follow teseos instructions



Code: [Select]
$mainPath = '/C:/wamp/www/'; // Change to your main domain installation root folder
try
Code: [Select]
$mainPath = 'C:/wamp/www/'; // Change to your main domain installation root folder


i think in this code, "$resource" gets the url of image to save in second osclass not main osclass
$currentFolder = osc_base_path().$resource['s_path'];

no, $resource['s_path'] contains only the part in ../uploads/..

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Several installations sharing same database and images folder [Solved]
« Reply #42 on: October 03, 2017, 12:33:41 am »

try
Code: [Select]
$mainPath = 'C:/wamp/www/'; // Change to your main domain installation root folder

Thank you Liath, this workedddddd  ;) :D
now it saves the images in main osclass when i'm submitting an item from second osclass. (C:\wamp\www\oc-content\uploads\1)  :)
but now i have just one problem. when i delete an item, it dosn't delete item's images from(C:\wamp\www\oc-content\uploads\1)  ??? why?
you think code has lack of this ability? or i did something wrong?

« Last Edit: October 03, 2017, 12:47:02 am by Sophia_OS »

Liath

  • issues
  • Hero Member
  • *
  • Posts: 1346
  • </html> the end is always near
Re: Several installations sharing same database and images folder [Solved]
« Reply #43 on: October 03, 2017, 01:07:19 am »
maybe this can help, it is untested, but should work


Code: [Select]
function cust_item_delete_resources($itemID) {
    Item::newInstance()->deleteResourcesFromHD($itemID);
}   
   
osc_add_hook('after_delete_item', 'cust_item_delete_resources');


add this to your functions.php in second installation like the previous code from teseo
« Last Edit: October 03, 2017, 01:10:16 am by Liath »

Sophia_OS

  • Sr. Member
  • ****
  • Posts: 416
Re: Several installations sharing same database and images folder [Solved]
« Reply #44 on: October 03, 2017, 01:26:15 am »
maybe this can help, it is untested, but should work


Code: [Select]
function cust_item_delete_resources($itemID) {
    Item::newInstance()->deleteResourcesFromHD($itemID);
}   
   
osc_add_hook('after_delete_item', 'cust_item_delete_resources');


add this to your functions.php in second installation like the previous code from teseo

when i'm deleting an item, it gives me error
Fatal error: Call to undefined method Item::deleteResourcesFromHD() in C:\wamp\www\second\oc-content\themes\modern\functions.php on line 309
and line 309 is: 2nd line of your function: Item::newInstance()->deleteResourcesFromHD($itemID);