CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 How to get basename (original filename) in FileUpload component

Print topic Send  topic

Author Message
Markie


Posts: 251
Posted: 10/19/2008, 12:07 PM

With regard to PHP basename, http://nl3.php.net/basename , I want to get the original filename of a file while using the FileUpload component. I know it's possible to change some things in classes.php, but I don't want to do that in this case. I really like the timestamp in the filename after upload, but besides that, I also want to add the original filename (in a separate field of my database).

At the moment, I have this "Before Insert" custom code in the record grid:

$oldfilename = $Component->{FileUpload1}->GetValue($filename);
$original_filename = CCGetOriginalFileName($filename);
$Component->{Basename}->SetValue($original_filename);

In my record grid, I have a "hidden" field which I have named "Basename" and which is connected to the Basename field in my database.

I have added the "Before Process File > Get Original Filename" event to the FileUpload component.

At the moment, the new filename (with timestamp) is added to my database instead of the original "old" filename (without timestamp). I want to add the "old" filename.

Is there anything I can do ? Do I have to do something completely different ?

Markie
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL
View profile  Send private message
Gena

Posts: 591
Posted: 10/19/2008, 12:59 PM

try like this

  
$oldfilename = $Component->FileUpload1->GetValue();    
$original_filename = CCGetOriginalFileName($oldfilename );  
$Component->Basename->Value = $original_filename;  

_________________
Gena
View profile  Send private message
Gena

Posts: 591
Posted: 10/19/2008, 1:01 PM

and event is BeforeInsert
_________________
Gena
View profile  Send private message
Markie


Posts: 251
Posted: 10/19/2008, 2:47 PM

Hi Gena, thanks again for your kind and quick answers. I have tried it, but I still get the "new" filename (including timestamp etc.) as a result in my database field. What can be the reason of this...

Markie
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL
View profile  Send private message
Gena

Posts: 591
Posted: 10/19/2008, 3:18 PM

sounds strange. Followin code works as expected here:
  
//End upload_b_image_BeforeShow  
  
//Get Original Filename @47-10353880  
    $control_value = $Component->GetValue();  
    $original_filename = CCGetOriginalFileName($control_value);  
    $Component->SetValue($original_filename);  
//End Get Original Filename  

I mean that CCGetOriginalFileName function works. Try to check you code and events, republish etc...
_________________
Gena
View profile  Send private message
datadoit
Posted: 10/19/2008, 7:22 PM

May have to also put it in BeforeUpdate to update the database field if
the record already exists.
Markie


Posts: 251
Posted: 10/20/2008, 7:57 AM

I seem to have a very spooky system.
To be sure I work with clean code, I have made a new page.
On this page, I did add a record grid ("uploaded")
In this record grid, I did add a hidden field ("Basename"), which is connected to the Basename field in my database.

I did add an HTML uploadform to the record grid ("FileUpload1").

Now, I did add this BeforeInsert custom code to the RECORD grid:

$oldfilename = $Component->FileUpload1->GetValue();
$original_filename = CCGetOriginalFileName($oldfilename );
$Component->Basename->Value = $original_filename;

I did add the "Before Process File > Get Original Filename" event to the FileUpload component.

In my mind I have done everything right. However, when I upload a file I see the NEW filename (with timestamp etc.) in the Basename field of the database. I really want to get the ORIGINAL filename (without timestamp etc.) in the Baseline field of the database.

I'm loosin' my mind ...

M@rkie
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL
View profile  Send private message
Gena

Posts: 591
Posted: 10/20/2008, 8:03 AM

too diffucult to say sthg... if you want you can send me you table dump file so I can try it here...
_________________
Gena
View profile  Send private message
Markie


Posts: 251
Posted: 10/20/2008, 8:56 AM

Hi Gena, I have analyzed me problem thoroughly now and it seems something is corrupt in my Classes.php file. I have tried a Classes.php file from another project and now I see the original filename appears in my Baseline field. But, of course there are errors because of the fact this Classes.php is not belonging to this project.

So... it seems you have helped me find the answer to my problem. Only now I have to find the corruption in my Classes.php file :-)

M@rkie
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL
View profile  Send private message
Gena

Posts: 591
Posted: 10/20/2008, 9:07 AM

Hmm... Do you remember I suggested you to not edit "system" php files, especialy grey areas... OK, try this. Save you current currupted file (for future reference). Then delete it and press F9 to regenerate all! This file should be regenerated again. Then compare your old currupted file and new one and make changes you have made before (BUT again I would suggest to NOT edit grey areas! you can use just balnk lines and insert code....). If you really need to change some functions (that I would not suggest again) just create a new one with the different name and use it...
_________________
Gena
View profile  Send private message
Markie


Posts: 251
Posted: 10/20/2008, 9:55 AM

Shame on me :(
However, this is a valuable lesson.
I have regenerated the Classes.php file and now everything works like a charm.
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL
View profile  Send private message
Gena

Posts: 591
Posted: 10/20/2008, 10:57 AM

great that it works!

Personally I prefer to create my onw php file that contains my functions. Then I include it in the Common.php (in editable section of course).

The second way I use is to override existing CCS functions (when it is possible) for example in Common.php. Each function there is surrounded by editable line so you can just comment it in this way:

  
/*  THIS was a blank line  -- so now it is commented  
//CCLogoutUser @0-AB918F3E  
function CCLogoutUser()  
{  
    CCSetSession("msUserID", "");  
    CCSetSession("msUserLogin", "");  
    CCSetSession("msGroupID", "");  
}  
//End CCLogoutUser  
*/   THIS was a blank line  --   so now it is commented  
  
// and here there is my version  
function CCLogoutUser()  
{  
    CCSetSession("msUserID", "");  
    CCSetSession("msUserLogin", "");  
    CCSetSession("msGroupID", "");  
    CCSetSession("msD", "");  
   //etc  
  
}  
 
be careful with this way.

btw thanks for your help O:)
_________________
Gena
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.