Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

How can I add sub-directories in the images folder???


ronald

Recommended Posts

Right now, you have to do everything manually. I.e. you have to manually create the directories, and you have to manually enter them into the database with a tool like phpMyAdmin.

 

Hth,

Matt

Link to comment
Share on other sites

FTP is a wonderful thing. If you have FTP access, just ftp up your photos/images where you want them to be and enter the path in the images box in the admin. Then you don't have to use the osc admin upload feature.

[no external urls in signatures please, kthanks]

Link to comment
Share on other sites

  • 3 weeks later...

yes but can t we make a modification in the code of the admin where u give the path of the image so that it will automaticully moved to another directory like catalog/images/categories or products depending of what we are adding ?

MS2

Link to comment
Share on other sites

yes but can t we make a modification in the code of the admin where u give the path of the image so that it will automaticully moved to another directory like catalog/images/categories or products depending of what we are adding ?
I thought of doing this, but to do it right, I would want to be able to browse to it (which would require a decent amount of coding to get right, since there is no server side version of a FILE box). However, if you just want to add a text box, that shouldn't be too hard. You would want to use the ->set_destination function on your upload object with the contents of the new text field.

 

Btw, someone posted that they got the wiki method working with MS2. Not sure if there was anything special about their situation.

 

Hth,

Matt

Link to comment
Share on other sites

i wrote a utility for doing this sometime ago

 

I know everyone tells you to do a database backup before trying something - but I can't stress enough to do it before running this code. It will alter every product in your database. Also keep a copy of your images somewhere else until you are happy it has done the correct thing.

 

It takes the current image location and moves it to its correct directory structire for categories and sub-categories and then rewirtes the database to reflect the new locations.

 

It will make the new directories automatically.

 

The way I tended to use it was to run it now and again when the images directory got out of hand - and it would clean everything up for you.

 

it does work - but run it at your own risk folks.

 

<?php

/**

* $Id: repair_thumbs.php,v 1.0 Exp $

* [email protected]



* osCommerce, Open Source E-Commerce Solutions

*

* http://www.oscommerce.com

*

* Copyright (c) 2003 osCommerce

*

* Released under the GNU General Public License

*/



require('includes/application_top.php');



require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_PRODUCT_INFO);



?>

<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">

<html <?php echo HTML_PARAMS;

?>>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET;

?>">



<title><?php echo TITLE ?></title>



<base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">



<link rel="stylesheet" type="text/css" href="<?php echo THEMA_STYLE;

?>">

</head>

<pre>

<!-- header //-->



<?php require(DIR_WS_INCLUDES . 'header.php');

?>



<!-- header_eof //-->

<?php

function deldir($dir)

{

       $current_dir = opendir($dir);

       while ($entryname = readdir($current_dir)) {

               if (is_dir("$dir/$entryname") and ($entryname != "." and $entryname != "..")) {

                       deldir("${dir}/${entryname}");

               } elseif ($entryname != "." and $entryname != "..") {

                       unlink("${dir}/${entryname}");

               }

       }

       closedir($current_dir);

       rmdir(${dir});

}



function get_cats($categories_array = '', $parent_id = '0', $indent = '') {



   global $languages_id;

$parent_id = tep_db_prepare_input($parent_id);



   if (!is_array($categories_array)) $categories_array = array();





   $categories_query = tep_db_query("select c.categories_id, cd.categories_name from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where parent_id = '" . tep_db_input($parent_id) . "' and c.categories_id = cd.categories_id and cd.language_id = '" . $languages_id . "' order by sort_order, cd.categories_name");

   while ($categories = tep_db_fetch_array($categories_query)) {



  $cat_string = str_replace("&", "", $categories['categories_name']);

  $cat_string = str_replace(" ", "", $cat_string);

  $cat_string = str_replace("nbsp", "", $cat_string);

  $cat_string = str_replace("/", "", $cat_string);

  $cat_string = str_replace(";", "", $cat_string);



echo $cat_string . "<br>";

     $categories_array[] = array('id' => $categories['categories_id'],

                                 'text' => $indent . $cat_string);





     if ($categories['categories_id'] != $parent_id) {        $categories_array = get_cats($categories_array, $categories['categories_id'], $indent . $cat_string . '/' );

     }

   }return $categories_array;}

$categories_array = get_cats($cPath, '', '');







$num_cats = count($categories_array);

//print_r($categories_array);



for ($i = 0; $i < $num_cats; $i++) {

       $cat_string = $categories_array[$i]['text'];



       echo $cat_string . "<BR>";

       // deldir(DIR_FS_CATALOG . DIR_WS_IMAGES . $cat_string);

       if (!file_exists(DIR_FS_CATALOG . DIR_WS_IMAGES . $cat_string)) {

               mkdir(DIR_FS_CATALOG . DIR_WS_IMAGES . $cat_string, 0777);

               }        $products_query = tep_db_query("select * from products_to_categories where categories_id = '" . $categories_array[$i]['id'] . "'");



       while ($products = tep_db_fetch_array($products_query)) {

               echo $products['products_id'] . ", ";

               $products_desc_query = tep_db_query("select products_image from products where products_id = '" . $products['products_id'] . "'");

               while ($products_desc = tep_db_fetch_array($products_desc_query)) {

                       $image = DIR_FS_CATALOG . DIR_WS_IMAGES . $products_desc['products_image'];

                       if (file_exists($image)) {

                               $image2 = explode('/', $image);

                               $new_image = DIR_FS_CATALOG . DIR_WS_IMAGES . $cat_string . '/' . $image2[count($image2)-1];



                               if ($new_image != $image) {

                                       if (!file_exists($new_image))

                                               copy($image, $new_image);                                        

         if (file_exists($new_image)) {                                                

        	 tep_db_query("update products set products_image = '" . $cat_string . '/' . $image2[count($image2)-1] . "' where products_id = '" . $products['products_id'] . "'");

                                      	 unlink($image);

                                       }                                

       }

                       }

               }        

 }

}

?>

</pre>

</body>

</html>

<?php require(DIR_WS_INCLUDES . 'application_bottom.php');?>

Link to comment
Share on other sites

WOW !!! I's awesome , u have anew big fan - this is incredible how when ur php skilled u can save days of works !

 

im about to test it on a osc 2.2 ms& ian load 5 , u think it could work ?

 

and what about the new products that u add after we used you script ?

 

can we use it again and it will move only the new products ?

MS2

Link to comment
Share on other sites

and also if u have a categories with spacezs in the names like "ide controlleurs" , how does it handle the space since in an url a space is not the best :-( maybe it changes the space and all the forbidden caracteres by a _ underscore ?

MS2

Link to comment
Share on other sites

yes it just moves products that are in the wrong place. At the moment it converts categories into a string - so for example

 

My First Category gets a Directory called MyFirstCategory.

 

it will also strip out slash characters and ampersands from a category name if they are there.

Link to comment
Share on other sites

Hi meltus,

 

Any special requirements we should be aware of before trying this?

Does the script try to CHMOD the images to 777?

 

Warning: copy(): SAFE MODE Restriction in effect. The script whose uid is 10028 is not allowed to access /home/httpd/vhosts/mysite.com.au/httpdocs/store/images/Action owned by uid 48 in /home/httpd/vhosts/mysite.com.au/httpdocs/store/image.php on line 99



Warning: copy(/home/httpd/vhosts/mysite.com.au/httpdocs/store/images/Action/stormymonday.gif): failed to open stream: No such file or directory in /home/httpd/vhosts/mysite.com.au/httpdocs/store/image.php on line 99

17, 

Warning: copy(): SAFE MODE Restriction in effect. The script whose uid is 10028 is not allowed to access /home/httpd/vhosts/mysite.com.au/httpdocs/store/images/Action owned by uid 48 in /home/httpd/vhosts/mysite.com.au/httpdocs/store/image.php on line 99

 

Tanks MaxiDVD

Link to comment
Share on other sites

to fix that you would either have to turn safe mode off on your server or using relative directories might help.

 

Either that or you could change the permissions on your images directories before starting.

 

Perhaps doing a chmod in the code after creating the directory might help you. I didn't get any of the warnings you described - I'm just speaking generally.

 

If all else fails you can run the script locally and then move it to your live server - but that might be a drag.

 

Have a sniff around the php boards about safe mode - or perhaps someone can will know more about it than I do on these boards.

Link to comment
Share on other sites

  • 1 month later...

This sounds like something I would like to use, but I don't know how.

 

Do I paste this into a .php document and post it on our site...?

 

Thanks,

Raoul

Link to comment
Share on other sites

Looks great ran it as a standalone php did not run on ms2 I'm afraid ??

had trouple with filename_product_info

changed that to use file directly and then hit this.

beyond me!!

is there an ms2 version available by chance it would be GREAT and it could be good to enter it in contributions to make it easier to find and support ?

 

Cannot redeclare tep_db_connect() (previously declared in /homepages

 

 

database.php on line 13

 

 

 

 

cheers David

Link to comment
Share on other sites

You can remove the line that references FILENAME_PRODUCT_INFO it isn't needed. I haven't run it on MS2 but I dont see why it wouldn't work.

 

I might polish it up and release as a contribution if there is any interest.

Link to comment
Share on other sites

I just tried it with MS2 - worked fine for me

 

The only thing I had to do was to set the permissions on the images directory so the script could create the directories.

 

I had a clean install of MS2. Copied the code from the post and pasted into a new file which I called repair_thumbs.php. Then I ran the script from my browser and it changed all the images to new directories.

Link to comment
Share on other sites

Meltus-

 

I definitely think this should be a contribution - it will save lots of time!

 

Am having some trouble getting it to work on my site, though. I have created and uploaded a 'repair_thumbs.php' and am getting the following error when I try to view the page:

 

Parse error: parse error in /u/htdocs/shelte/catalog/repair_thumbs.php on line 35

 

 

Line 35 is:

 

$current_dir = opendir($dir);

 

I have changed permissions on all file to maximum read/write/execute permisions (chmod 777).

 

Any ideas?

 

Thanks,

Raoul

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...