This topic is locked

Replace sace in image name

9/20/2006 9:39:35 PM
ASPRunnerPro General questions
A
artistscope author

I have created an app for adding products to a catalogue and have a problem when a user uploads an image that contains a space in the file name. Ordinarily this is not a problem except that I am using aspx image resampling to display the image at widths set per category/default settings. If an an image contains a space in it's file name, an error occurs.
So I would lke to add code to replace any spaces with an underscore, but where excatly?
If you can recommend exactly where and what routine to add, it will be greatly appreciated... ASP Runner Pro.
This feature is something that could be included in your next release?

A
artistscope author 9/26/2006

Bump

Sergey Kornilov admin 9/27/2006

Here is how you can do this in ASPRunnerPro 4.1.
Open generated edit or add page in text editor and find code snippet this one and apply changes in bold.

If ctype = "upload2" Then

' write file

strValue = Replace(strValue, " ", "_")

rs("Model")= strValue

if strValue<>"" then _

WriteToFile Server.MapPath(GetUploadFolder("Model","") & strValue), GetRequestForm("file_Model")

end if

A
artistscope author 9/30/2006

Here is how you can do this in ASPRunnerPro 4.1.


Unfortunately the scripts were created using 4.0 and have been extensively customised. I Can't find anything like the code mentioned in either 4.0 or 4.1.
Where exactly should the code be modified??

Sergey Kornilov admin 10/1/2006

Search for WriteToFile function. This function takes as a first parameter full file name with path.

Before calling this function make sure spaces are replaced with underscores. See my sample code for more info.

A
artistscope author 10/1/2006

Search for WriteToFile function. This function takes as a first parameter full file name with path.

Before calling this function make sure spaces are replaced with underscores. See my sample code for more info.


In item_add.asp...
if IsUpdatable(rs.Fields("PROD_IMAGE")) then
strValue=dict("PROD_IMAGE")

if GetEditFormat("PROD_IMAGE")=EDIT_FORMAT_FILE then

if GetRequestForm("typePROD_IMAGE") = "upload2" then

rs("PRODIMAGE")= strValue

if strValue<>"" then


WriteToFile Server.MapPath(GetUploadFolder("PROD_IMAGE") & strValue), GetRequestForm("filePROD_IMAGE")

end if

elseif GetEditFormat("PROD_IMAGE")<>FORMAT_DATABASE_IMAGE and GetEditFormat("PROD_IMAGE")<>FORMAT_DATABASE_FILE then

if IsFloat(nType) and strValue<>"" then

rs("PROD_IMAGE") = CDbl(strValue)

else

rs("PROD_IMAGE") = strValue

end if
else

if GetRequestForm("typePROD_IMAGE") = "file1" or GetRequestForm("typePROD_IMAGE") = "file2" then

If IsNull(strValue) or GetRequestForm("typePROD_IMAGE") = "file1" Then

rs("PROD_IMAGE") = Null

Else

rs("PROD_IMAGE").AppendChunk strValue

End If

end if

end if

end if

=================================

or in commonfunctions.asp...
sub WriteToFile(strFileName, binData)

Dim rsT

Set rsT = Server.CreateObject("ADODB.Recordset")

rsT.Fields.Append "File", 205, LenB(binData)

rsT.Open

rsT.AddNew

rsT.Fields("File").AppendChunk binData & ChrB(0)

rsT.Update
Dim stream

Set stream = Server.CreateObject("ADODB.Stream")

stream.Type = 1

stream.Open

stream.Write rsT.Fields("File").GetChunk(LenB(binData))

stream.SaveToFile strFileName, 2
stream.Close

Set stream = Nothing

rsT.Close

Set rsT = Nothing

end sub

==========================
Which one should be modified?

Sergey Kornilov admin 10/1/2006

rs("PRODIMAGE")= strValue

**strValue = Replace(strValue, " ", "")**

if strValue<>"" then _

WriteToFile Server.MapPath(GetUploadFolder("PROD_IMAGE") & strValue), GetRequestForm("filePROD_IMAGE")

end if

A
artistscope author 10/1/2006

This doesn't change the file name in the _add.asp page fields or the image name saved to the server.
It needs to be altered when saving the image to the server, and also when adding/updating the database field.

Sergey Kornilov admin 10/3/2006

Revised:

strValue = Replace(strValue, " ", "_")

rs("PRODIMAGE")= strValue

if strValue<>"" then


WriteToFile Server.MapPath(GetUploadFolder("PROD_IMAGE") & strValue), GetRequestForm("filePROD_IMAGE")

end if

A
artistscope author 10/4/2006

Revised:


Thanks, that worked for the _edit.asp page but on the _add.asp page it doesn't alter anything...
=================================

if IsUpdatable(rs.Fields("PROD_IMAGE")) then

>>>

strValue=dict("PROD_IMAGE")

>>>

if GetEditFormat("PROD_IMAGE")=EDIT_FORMAT_FILE then

if GetRequestForm("typePROD_IMAGE") = "upload2" then

>>>

rs("PRODIMAGE")= strValue

>>>

if strValue<>"" then


WriteToFile Server.MapPath(GetUploadFolder("PROD_IMAGE") & strValue), GetRequestForm("filePROD_IMAGE")

end if

elseif GetEditFormat("PROD_IMAGE")<>FORMAT_DATABASE_IMAGE and GetEditFormat("PROD_IMAGE")<>FORMAT_DATABASE_FILE then

if IsFloat(nType) and strValue<>"" then

rs("PROD_IMAGE") = CDbl(strValue)

else

rs("PROD_IMAGE") = strValue

end if
else

if GetRequestForm("typePROD_IMAGE") = "file1" or GetRequestForm("typePROD_IMAGE") = "file2" then

If IsNull(strValue) or GetRequestForm("typePROD_IMAGE") = "file1" Then

rs("PROD_IMAGE") = Null

Else

rs("PROD_IMAGE").AppendChunk strValue

End If

end if

end if

end if

===================================
Where >>> appears is where I have already tried the replace function.

Sergey Kornilov admin 10/4/2006

Make sure you doing replace before assigning a value to recordset variable.

A
artistscope author 10/4/2006

Make sure you doing replace before assigning a value to recordset variable.


Ok, but where?

J
Jane 10/6/2006

Check that you doing replace before assigning a value to recordset variable in the code you posted above.