Markie
Posts: 251
|
| Posted: 10/15/2008, 8:35 AM |
|
At the moment I'm working with the file upload form. Everything is working and I like the fact the uploaded file gets a timestamp (for example: 200810151719100.myphoto.jpg).
Is it also possible to add the username (CCGetUserLogin() name) to the uploaded photo ? for example: 200810151719100.Markie.RPHO jr 328.jpg
This wil definitely help me find out which photos belong to which users of my photo gallery.
Maybe it's quite simple but I'm a little stuck at the moment.
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 |
 |
 |
Gena
Posts: 591
|
| Posted: 10/15/2008, 9:06 AM |
|
Yes, look at event like AfterProcessFile. Here you can catch your original name:
like
$filenamSRC = $Component->FileUpload1->GetValue() ;
so you can change it as you need and ever rename original image file...
_________________
Gena |
 |
 |
Gena
Posts: 591
|
| Posted: 10/15/2008, 9:11 AM |
|
and to put your new name in db use BeforeInsert event:
$Component-> you_name_field ->Value = filenamehere ;
_________________
Gena |
 |
 |
Markie
Posts: 251
|
| Posted: 10/15/2008, 9:30 AM |
|
I don't get it. I want to keep the filename with the timestamp, it's great. I
All I want is to ADD the CCGetUserLogin() name to the filename.
so, after upload the filename has to be something like this:
200810151719100.Markie.mypicture.jpg
Is this possible with an Event ?
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 |
 |
 |
Gena
Posts: 591
|
| Posted: 10/15/2008, 9:42 AM |
|
I wrote you already - you get the original filename and aftre you can (using php function) change it as you want...
_________________
Gena |
 |
 |
Markie
Posts: 251
|
| Posted: 10/15/2008, 11:09 AM |
|
Thank you for your patience but this topic seems rather difficult for me.
When I use AfterProcessFile:
$filenamSRC = $Component->FileUpload1->GetValue() ;
This is the result:
Fatal error: Call to a member function GetValue() on a non-object in C:\xampp\htdocs\project\uploader_events.php on line 22
Any advice ?
_________________
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 |
 |
 |
Gena
Posts: 591
|
| Posted: 10/15/2008, 11:23 AM |
|
that was an example
you need to use your real component name, not my FileUpload1
_________________
Gena |
 |
 |
Markie
Posts: 251
|
| Posted: 10/15/2008, 12:36 PM |
|
silly me 
While reading other postings regarding this topic I found the most simple solution. In the file classes.php you can find the clsFileUpload Class. At the end of this class there's this line:
$ActualFileName = date("YmdHis") . $index . "." . $FileName;
I have changed this to:
$ActualFileName = date("YmdHis") . $index . "." . CCGetUserLogin() . $FileName;
and now all uploaded files contain the username too. This is where I was after.
Thanks for your patience,
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 |
 |
 |
Gena
Posts: 591
|
| Posted: 10/15/2008, 12:56 PM |
|
no, you are not alone! Sometime it happened to me too. But this kind of error exactly means that something wrong with the names...
_________________
Gena |
 |
 |
Gena
Posts: 591
|
| Posted: 10/15/2008, 12:59 PM |
|
I would not suggest you to change classes.php (especialy a grey areas) since it is regeneratable file...
_________________
Gena |
 |
 |
Markie
Posts: 251
|
| Posted: 10/21/2008, 6:36 AM |
|
Gena, regarding this topic I'm almost there. Almost everything works at the moment. I have added this "Before Insert" code and I can change the filename without editing classes.php:
$firstfilename = $Component->FileUpload1->GetValue();
$photographer = $Component->Photographer->GetValue();
$secondfilename = CCGetOriginalFileName($firstfilename );
$Component->Secondfilename->Value = (mktime() . "." . CCGetUserLogin() . "." . $photographer . "." . $secondfilename);
The new filename with all bells and whistles appears in my database without errors.
Now, I also want the new filename to be the filename of the file I have uploaded (not only a new filename in my database, but also the file gets the new filename). Whatever I do, I can't seem to change the actual filename of the uploaded file. Do you have any advice ?
What additional steps do I have to take ?
_________________
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 |
 |
 |
Markie
Posts: 251
|
| Posted: 10/21/2008, 8:38 AM |
|
I think I'm on the right track with this AfterProcessFile code:
//Custom Code @20-2A29BDB7
// -------------------------
$old_name=$uploaded->FileUpload1->Getvalue();
$new_name="newname.jpg";
rename("uploaded/".$old_name,"uploaded/".$new_name);
// -------------------------
//End Custom Code
_________________
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 |
 |
 |
Gena
Posts: 591
|
| Posted: 10/21/2008, 8:44 AM |
|
opp... sorry for delay 
Sure you can do what you want with your original file using PHP function.
_________________
Gena |
 |
 |
girish_327
Posts: 108
|
| Posted: 01/24/2009, 7:44 AM |
|
I think this will help you brother.
$ActivityID = CCGetFromGet("activity_id","");
$old=$activity_documents1->FileUpload1->GetValue();
$FileExtension = substr(strrchr($old,"."),0,4);
$new= $ActivityID."_".CCGetUserLogin()."_".date("dmyGis").$FileExtension;
rename("activity_doc/".$old,"activity_doc/".$new);
$db=new clsDBlions(); //or whatever your db class is called
$db->query("update activity_documents set document='".$new."' where document='".$old."'");
_________________
Girish Baraskar
Web Designer/Developer
http://www.agnisdesigners.com
http://www.eindianpaintings.com
http://www.realestatekolhapur.com |
 |
 |
|