close ad
WARNING: Do Not Install the DREAMWEAVER CC 2017 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

file upload rename problems

Thread began 3/13/2013 3:32 pm by Christopher West | Last modified 3/18/2013 11:25 am by Christopher West | 1231 views | 9 replies |

Christopher WestCommunity Expert

file upload rename problems

Hi just having odd behaviour with some coding:

I have 2 pages one is ADD new image and the second is UPDATE image.

but im have a blonde moment it seems as for some reason I cannot get my head around the logic and I have tried different variations... for example of one of the variations that goes wrong....when an image uploads when it renames it creates a duplicate file extension on the new file on the server ( image.jpg.jpg) or it appends the file like so (image.jpg_1)

could you give me a rund down of which options to select for renaming:
from the Dynamic Data panel in File Manipulation Upload wizard I have many options to chose from ie:
1. Upload Files (imagefile)
status code
error messafe
client file name
file extension
server file name
service simple file name
.....
2 updateleaderboard (this is my html form)
imagefile
>imagefile Field Name
>imagefile temp path
>imagefile simple file name
.....

I have attached the 2 files to show my current image upload code....

All I want is to make sure the new file that's being uploaded will append _1 _2 etc on the end of the file (not on the end of .jpg extension as its currently doing)

Chris

Sign in to reply to this post

Jason ByrnesWebAssist

in the upload file behavior, the file name setting should be:
[FileName]

you are binding the file name setting to the file field in the form, this is causing the probelm, set that to "[FileName]" instead.

Sign in to reply to this post

Christopher WestCommunity Expert

You are a life saver :) that's the one variation I hadn't tried lol I feel like such a fool I didn't think of that one :) Thanks Jason... Perfect
Chris

Sign in to reply to this post

Christopher WestCommunity Expert

oh Jason one question concerning the use of [FileName] ....how would I perform lowercase and replacement string functions as on another site I build I used:

<?php echo strtolower(str_replace(" ", "-", (((isset($_FILES["fileField"])))? preg_replace('/.[^.]*$/', '', $_FILES["fileField"]["name"]) :""))); ?>

How would I incorporate strtolower and str_replace functions?

Chris

Sign in to reply to this post

Jason ByrnesWebAssist

add the following code at line 1 of your page:

php:
<?php 

if(isset($_FILES)) { 
    foreach(
$_FILES as $k => $v) { 
        
$_FILES[$k]["name"] = strtolower(str_replace(array(" ","-","\\","'"), ""preg_replace('/.[^.]*$/'''$_FILES[$k]["name"]))); 
    } 

?>



if there are any files being uploaded, it will automatically parse each one to convert the file name using strtolower, str_replace and the preg_replace functions

Sign in to reply to this post

Christopher WestCommunity Expert

Hi Jason, that piece of code works for adding new records. however if I have an image already on the server it does rename the file in the database and appends _1 however it doesn't include the .jpg extension and on the server where the file is save to it wont show as an image since the .jpg extension on the physical file on the server is missing. the .jpg extension will be fine if a new file is uploaded with a unique name..it just cuts it off if uploads same file name. any suggestions?

Chris

Sign in to reply to this post

Jason ByrnesWebAssist

it wont be able to fix the existing bad file names.

you will either need to re upload those files, or manually change the file names on the server and in the database.

Sign in to reply to this post

Christopher WestCommunity Expert

Hi Jason, you have lost me there...what bad file names you referring to? What I was saying is that is does change the filename but it chops of the file extension from the renaming process thus the new file has no file extension associated with it either on the server or the newly saved record in the database. so to recap it does change the filename but it loses the file extension. so is that what you were referring to?

Chris

Sign in to reply to this post

Jason ByrnesWebAssist

I think you have lost me.
I have created a support ticket so we can look into this issue further.

To view and edit your support ticket, please log into your support history:
supporthistory.php

If anyone else is experiencing this same issue, please append to this thread.

Sign in to reply to this post

Christopher WestCommunity Expert

Jason just a quick update..first thanks for the help the other night greatly appriciated...after you helped me I investigated why the original code I had worked on a previous website and not this current one....what I found was it was the function preg_replace that was making the code in the previous website working...hence why the following code was working inside the actual file upload behaviour using the fieldname of the file rather then [FileName]

<?php echo strtolower(str_replace(" ", "-", (((isset($_FILES["fileField"])))? preg_replace('/.[^.]*$/', '', $_FILES["fileField"]["name"]) :""))); ?>

Because the above code uses preg_replace what it was doing was manipulating the file extension (correcting it in my database) In other words it as a silly method I was using as the above code was basically ruining the filename but then correcting it by using the preg_replace....thats why when you helped me you had changed your code to not use preg_replace since it was removing the file extension :)

Chris

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...