CodeCharge Studio
search Register Login  

Web Reporting

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

YesSoftware Forums -> CodeCharge Studio -> PHP

 Rename a file after upload (File Upload)

Print topic Send  topic

Author Message
Caiorr

Posts: 8
Posted: 05/29/2009, 1:02 PM

Hi all,

Is possible rename a file when i uploading it using the File Upload? I need that because my client didnt liked the name that CCS create for the file (mask + filename.xxx).

Or if was possible just disallow this mask that CCS put on file name. !!!
View profile  Send private message
jjrjr1


Posts: 942
Posted: 05/29/2009, 11:14 PM

Hi

Yes but Why would you want to do that???

CCS does that so that no two files will have the same name.

For example let's say 2 users upload a file with the name image.jpg...

Which file would get erased or stepped on???

The stuff CCS appends to the file is only just date & time stamp added to the file name to ensure unique file names.

Why is your client complaining??

If you wrote the application correctly, when the file name is displayed on a page all you have to do is call the function in the on before show event to show the original file name. That is a built in CCS function. In other words, your client should never see the name CCS gave the uploaded file....

I am confused as to why you want to do this.

But if you really want to rename the file name, do it in the after process file event for the upload control. Don't forget to change the database entry for the file name as well, along with whatever changes you need to make to access the uploaded file later.

I think you are making things much more difficult for yourself.

Also be sure when you rename the file, that the new file name does not already exist.

I think you would be making more work for yourself by doing this, not to mention keeping track of all the files uploaded.

BTW if you have this question a better thing for you to worry about, if you are on a linux server, is uploading files with spaces in the filename. HINT: http://forums.yessoftware.com/posts.php?post_id=98309&s_keyword=filename.

Incidentally if you want CCS to stop adding the timestamp to the file name, here is where you would remove the line that adds it.

Good Luck

I have to say... Hard not to GAZA a post like this... :-)

_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com
View profile  Send private message
DonP
Posted: 05/31/2009, 10:06 AM

I always rework the upload to make more consistent file names for the
very reason that jjrjrl says I shouldn't want to do so! I don't want
multiple copies of the same file but with different names. Why should I?
If I need version control, I can do that myself on my PC. If I upload
image.jpg, I want to upload image.jpg, not imagetimestamp.jpg.

Don (DonP)

jjrjr1 wrote:
> Hi
>
> Why would you want to do that???
>
> CCS does that so that no two files will have the same name.
>
> For example let's say 2 users upload a file with the name image.jpg...
>
> Which file would get erases??? The stuff CCS appends to the file is only just
> date & time stamp added to the file name to ensure unique file names.
>
> Why is your client complaining?? If you wrote the application correctly, when
> the file name is displayed on a page all you have to do is call the function in
> the on before show event to show the original file name. That is a built in CCS
> function.
>
> I am confused as to why you want to do that.
>
> But if you really want to rename the file name do it in the after process
> filename event for the upload control. Don't forget to change the database
> entry for the file name as well.
>
> I think you are making things much more difficult and also be shure when you
> rename the file the new file name does not already exist.
>
> Good Luck
>
> _________________
> More CodeCharge Studio Support at - http://CCSElite.com
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.yessoftware.com/
>
jjrjr1


Posts: 942
Posted: 05/31/2009, 12:59 PM

Hi Don

You are absolutely correct. Always rework the file names if that is your requirement.

But for most web sites that visitors upload files, you can't see the problem particularly if it has any volume??

For example.... You create a web site for photo or video sharing..

Now there is one visitor, mm... let's say Mary in Ohio, who took a picture of her dad and she happened to name it, of all things, DAD.JPG..

Mary now uploads the file on your site. What do you save DAD.JPG as the file on the server??? Just "DAD.JPG"??

Now in San Jose, Lucy, who also loves her dad takes a picture of her dad.... and what do you know she named it DAD.JPG also...

Now Lucy also uploads her dear dads photo. Do you check to see if there is already a file with that name? Do you overwrite it? or maybe change it? Wonder how to make it unique?

Maybe use a timestamp??

Or does Mary's DAD bite the dust???? ..... (There's Something About Mary... Hair Gel??)

I would be interested in other solutions. It would be a big help.
Or maybe you are just creating CCS applications for only one user???
Let me know so I can understand.

Thanks in advance Don

John





_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com
View profile  Send private message
peterr


Posts: 5971
Posted: 05/31/2009, 3:11 PM

Hi,

Yes, this is done for many reasons: file name conflict resolution, multi-user environment (every website), and security - for example you may not want an unauthorized employee to guess and open or replace files like "salaries.xls".
The solution provided within CCS is very typical in professional web development and preventing important mistakes without thinking about all the consequences.
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
jjrjr1


Posts: 942
Posted: 05/31/2009, 3:15 PM

Yup Peter.. That's the whole story exactly.

John

_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com
View profile  Send private message
yogiyang

Posts: 26
Posted: 06/02/2009, 6:21 AM

I have not done this in CCS but my PHP knowledge tell that you can always use:
- move_uploaded_file(location/CCS_File_name, location/the_name_you_want) -- this will remove the file as created by CCS on server and copy it to the name and location you specified.
- copy(location/CCS_File_name, location/the_name_you_want) -- this will copy the file keeping the existing file.

functions provided in php

This way you can always get the name of file as you want but as others have warned you don't blame anyone except yourself if any files are overwritten by mistake. O:)

HTH

_________________
Regards,

Yogi Yang
View profile  Send private message
girish_327


Posts: 108
Posted: 07/30/2009, 10:19 PM

Hello ,

I used following script for resizing image and renaming file after upload

I put this code AfterProcessFile Event

  
  
global $DBrealestatekolhapur;  
  
$PropertyID = CCGetFromGet("Property_ID");  
$PropertyName = CCDLookup("Project_Name","properties","Property_ID=".$PropertyID,$DBrealestatekolhapur);  
  
  
include_once("Scripts/resize.php");  
$thumb=new thumbnail("kolhapur-property-current-status/large/". $current_status1->Current_Status->GetValue()); // prepare to generate "shiegege.jpg" in directory "/www"  
$thumb->size_width(680);		   // set width for thumbnail with 100 pixels  
$thumb->save("kolhapur-property-current-status/large/".$current_status1->Current_Status->GetValue());	   // save my  thumbnail to file "huhu.jpg" in directory "/www/thumb  
  
//include_once("Scripts/resize.php");  
$thumb=new thumbnail("kolhapur-property-current-status/large/". $current_status1->Current_Status->GetValue()); // prepare to generate "shiegege.jpg" in directory "/www"  
$thumb->size_width(150);		   // set width for thumbnail with 100 pixels  
$thumb->save("kolhapur-property-current-status/thumb/".$current_status1->Current_Status->GetValue());	   // save my  thumbnail to file "huhu.jpg" in directory "/www/thumb  
  
$old= $current_status1->Current_Status->GetValue();  
$PropertyName = str_replace(" ","-",$PropertyName); // Replace White Space with (-)Hyphen  
$FileExtension = substr(strrchr($old,"."),0,4);    
$new= $PropertyID. "-". $PropertyName."-".date("dmyGis").$FileExtension;  
rename("kolhapur-property-current-status/large/".$old,"kolhapur-property-current-status/large/".$new);  
rename("kolhapur-property-current-status/thumb/".$old,"kolhapur-property-current-status/thumb/".$new);  
  
$db=new clsDBrealestatekolhapur(); //or whatever your db class is called  
$db->query("UPDATE current_status SET Current_Status='".$new."' where Current_Status='".$old."'");  
  

_________________
Girish Baraskar
Web Designer/Developer
http://www.agnisdesigners.com
http://www.eindianpaintings.com
http://www.realestatekolhapur.com
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.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


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