The Joomla! Forum ™



Forum rules


Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.



Post new topic Reply to topic  [ 11 posts ] 
Author Message
PostPosted: Sun Apr 22, 2012 12:44 pm 
User avatar
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Sun Sep 21, 2008 3:31 am
Posts: 214
Hi,
Ive added an Image upload form field to my component,
Everything is going right, but I have a little problem:
Code:
for($i=0;$i<count($images['name']);$i++){
         if($images['error'][$i]!=4){
            $imagename = JFile::makeSafe($images['name'][$i]);
            $imagesrc = $images['tmp_name'][$i];
            $imagedest = "images/myimages/$imagename";
            if(JFile::upload($imagesrc, $imagedest))
               $img[]=$imagedest;
            else
               $img[]="images/myimages/noimage.jpg";
            $data['images']=implode(',',$img);
         }else{
            $this->setError($images['error'][$i]);
            return false;
         }
      }

root folder for upload files is joomlaroot/administrator,
this means that all images will be uploaded in joomlaroot/administrator/images
How do I must change the address so the files will be uploaded in joomlaroot/images ??

_________________
http://www.joomlux.com - Joomla! Extensions and Templates


Top
 Profile  
 
PostPosted: Sun Apr 22, 2012 1:47 pm 
User avatar
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Sun Sep 21, 2008 3:31 am
Posts: 214
I've checked, All path constants are defined inside of administrator/index.php
so there is no use in them...

_________________
http://www.joomlux.com - Joomla! Extensions and Templates


Top
 Profile  
 
PostPosted: Fri Apr 27, 2012 6:51 pm 
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Thu Oct 30, 2008 7:27 pm
Posts: 149
why not use "../"?:

Code:
$imagedest = "../images/myimages/$imagename";


Top
 Profile  
 
PostPosted: Sun Apr 29, 2012 6:27 pm 
User avatar
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Sun Sep 21, 2008 3:31 am
Posts: 214
Thnx Drewgg, The Idea works, but I have to make some other changes in order to save the correct address in database (we dont want ../images/myimages/example.jpg as address in database:
Code:
for($i=0;$i<count($images['name']);$i++){
         if($images['error'][$i]!=4){
            $imagename = JFile::makeSafe($images['name'][$i]);
            $imagesrc = $images['tmp_name'][$i];
            $dbimagedest = "images/myimages/$imagename";
            $imagedest = "../".$dbimagedest;
            if(JFile::upload($imagesrc, $imagedest))
               $img[]=$dbimagedest;
            else
               $img[]="images/myimages/noimage.jpg";
         }else{
            $this->setError($images['error'][$i]);
            return false;
         }
      }
$data['images']=implode(',',$img);

_________________
http://www.joomlux.com - Joomla! Extensions and Templates


Top
 Profile  
 
PostPosted: Thu May 03, 2012 10:12 am 
User avatar
Joomla! Exemplar
Joomla! Exemplar

Joined: Fri Sep 09, 2005 2:13 pm
Posts: 7954
Location: The Netherlands
What do you want in your database? Yo onl need the file name and the rest of the path can be hardcoded in your component? Or am I missing something? That's the way I am doing it. The path is to my component, and using the filename only in the database. When i am calling the images I am getting the path in the code

_________________
Robert Dam - Joomla Forum Moderator
Dutch Boards | Joomla Coding Boards | English Support Boards


Top
 Profile  
 
PostPosted: Sun May 06, 2012 8:29 am 
User avatar
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Sun Sep 21, 2008 3:31 am
Posts: 214
@Robert: In spite of the fact that it takes more resources (saving paths) is there any other benefit in saving only the file name?

_________________
http://www.joomlux.com - Joomla! Extensions and Templates


Top
 Profile  
 
PostPosted: Sun May 06, 2012 10:44 am 
Joomla! Ace
Joomla! Ace

Joined: Sat Oct 01, 2011 7:06 pm
Posts: 1260
The benefit of having the path stored once and not with every file is when it changes it only needs to be changed in one place.


Top
 Profile  
 
PostPosted: Sun May 06, 2012 12:17 pm 
User avatar
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Sun Sep 21, 2008 3:31 am
Posts: 214
@Sovainfo: I wanted to know if there is any benefits More that That!

_________________
http://www.joomlux.com - Joomla! Extensions and Templates


Top
 Profile  
 
PostPosted: Sun May 06, 2012 10:15 pm 
Joomla! Ace
Joomla! Ace

Joined: Sat Oct 01, 2011 7:06 pm
Posts: 1260
MeeDNite wrote:
@Sovainfo: I wanted to know if there is any benefits More that That!
That's why I gave you that answer. There is a difference between wasting some bytes of storage and having a need to write a complex procedure when the storage location changes.


Top
 Profile  
 
PostPosted: Mon May 07, 2012 7:44 pm 
User avatar
Joomla! Exemplar
Joomla! Exemplar

Joined: Fri Sep 09, 2005 2:13 pm
Posts: 7954
Location: The Netherlands
MeeDNite wrote:
@Robert: In spite of the fact that it takes more resources (saving paths) is there any other benefit in saving only the file name?

If you are saving only he filename the path can be different when changing the site structure for example. When you are saving the pah you need to change the database also when changing something.
In my opinion saving the filename only, you are more flexible

_________________
Robert Dam - Joomla Forum Moderator
Dutch Boards | Joomla Coding Boards | English Support Boards


Top
 Profile  
 
PostPosted: Thu May 10, 2012 5:38 pm 
User avatar
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Sun Sep 21, 2008 3:31 am
Posts: 214
Thats what I was lookin for, Thnx.
By The way I was lookin' for "Like" button under your post :D

_________________
http://www.joomlux.com - Joomla! Extensions and Templates


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 



Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group