This topic is locked

Renaming File Names

12/29/2010 1:34:36 PM
PHPRunner General questions
H
horsey_kim author

Link to the manual for the suggested code: Manual's Renaming Uploaded files
Not sure why, but I had to modify it a bit to work in my template. (I use windows xp, google chrome and PHPrunner V5.3 with the template Madrid and a modified version of Madrid. So it probably is something I did wrong that I had to modify the code a bit. I suggest you try what is in the manual first. Because it probably work the best. But if you have problems with the edit screen, you can try one of the altered code below. I am NOT an expert at all and struggle with this at times. This took several hours to find a combination in the code that worked for me. So don't rely on this as being what is right, it just functioned for my purpose... <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=16016&image=1&table=forumtopics' class='bbc_emoticon' alt=':)' /> Support knows way better than I.
CODE FOR SETTING THE EXACT FILE EXTENSION:
global $pageObject;

foreach( $pageObject->filesToMove as $key=>$val)

{ if($pageObject->filesToMove[$key]->sourceFilename==$_FILES[");

$pageObject->filesToMove[$key]->destFilename= $values["[color="#FF0000"]somefieldname"].".jpg";
$values[".".jpg";}
CODE FOR AUTO FILE EXTENSION BASED ON FILE TYPE:
global $pageObject;

$ext = substr(strrchr($values["[color="#FF0000"]filename"], '.'), 1);

foreach( $pageObject->filesToMove as $key=>$val)

{ if($pageObject->filesToMove[$key]->sourceFilename==$_FILES[");

$pageObject->filesToMove[$key]->destFilename= $values["[color="#FF0000"]somefieldname"].".".$ext;
$values["somefieldname"].".".$ext;}
CAUTION, For those who want to use the RECORD ID as part of the file name:

I might be wrong, but I understand that it is difficult to use record id as part of the name, from the add screen. I think the record id is not created until after the record is saved. But here is how I worked around it. I did a two step process. First on the add screen have all your fields you want without the upload field. Then when the record is saved, send it to the edit screen of that record and include the upload field on that screen. This will allow the add screen to create a record ID, that will allow the edit screen to upload and rename the file. If you have been successful in using the RECORD ID as part of the upload files name in the add screen, PLEASE let me know. I am always looking for better ways to accomplish something. I value your input <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=16016&image=2&table=forumtopics' class='bbc_emoticon' alt=':)' />
Kim

T
tedwilder 1/5/2011



Link to the manual for the suggested code: Manual's Renaming Uploaded files
Not but I understand that it is difficult to use record id as part of the name, from the add screen. I think the record id is not created until after the record is saved. But here is how I worked around it. I did a two step process. First on the add screen have all your fields you want without the upload field. Then when the record is saved, send it to the edit screen of that record and include the upload field on that screen. This will allow the add screen to create a record ID, that will allow the edit screen to upload and rename the file. If you have been successful in using the RECORD ID as part of the upload files name in the add screen, PLEASE let me know. I am always looking for better ways to accomplish something. I value your input <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=55401&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />
Kim


I dont get it.. why dont you first do a simple query to check what is the current last record id number and just add 1 to that number.. So very easy and all in one step.

$sql="select max(recordid) as lastid from yourtable order by lastid";

$rs=CustomQuery($sql);

$data=db_fetch_array($rs);

you have the $new_record_id_to_be_saved=($data["lastid"]+1);

file name is : $filename=$new_record_id_to_be_saved.$filenamewithoutid.$fileextension;
of course you have to enable " table locking" if they are many user because one user could enter a new file, so get last record id and add 1 while someone else would be doing the same and the lastrecordid would be wrong between the time the user fill the form and someone else enter one too.

H
horsey_kim author 1/5/2011

Great Idea!! I do have a question on table locking. What if you have a website that say 25 people might be on at the same time (classified or some social network), would table locking slow down the process for everyone? I have not used table locking before and this idea has got me curious if it would work for what I need.
Kim