Coldfusion搜索HTML< textarea>然后隐藏Base64字符串到服务器上的文件 [英] Coldfusion Search HTML <textarea> Then Covert Base64 String To File On Server

查看:150
本文介绍了Coldfusion搜索HTML< textarea>然后隐藏Base64字符串到服务器上的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:将textarea中的base64字符串替换为URL。 textarea是一个所见即所得的编辑器(CKEditor)。我需要将图像上传到服务器文件系统。我试图用这段代码将字符串转换为实际的图像,然后在textarea中用服务器(URL)上的图像位置替换base64字符串。

Replace base64 string that is in the textarea with a URL. The textarea is a WYSIWYG editor (CKEditor). I need to upload an image to the server file system. I'm trying to use this code to convert the string to an actual image and then in the textarea replacing the base64 string with the location of the image on the server (URL).

<cfset image = imageReadBase64(#LocalOccurrence#)>
<cfimage source="#image#" 
         destination="#save_image_to_this_location# 
         & #name_of_image#  
         & #extension_of_image#" 
         action="write"> 

原始问题:
使用ColdFusion,我试图找到在HTML内部的所有base64图像字符串,然后将它们各自保存为它自己的文件在服务器上,创建URL并插入到数据库中。

Original Question: Using ColdFusion, am trying to find all base64 image strings inside HTML then save each as its own file on the server, create URL, and insert into database. I need help crafting a loop at this point.

我用这段代码找到了一个base64字符串:

I got as far finding a single occurrence of the base64 string with this code:

<cfset textarea_to_search = #form.overview_text#>
<cfset string_base64_header = "base64,">
<cfset string_base64_ending = '"'>

<cfoutput>
  <cfset mystart = find(#string_base64_header#, #textarea_to_search#)>
  <cfset myend = find(#string_base64_ending#,#textarea_to_search#,#mystart#)>
  <cfset my64 = mid(#textarea_to_search#, (#mystart#+7), ((#myend#-7)-#mystart#))>
  <span style=font-size:8px;"> #mystart#, #myend#, #my64#</span>
</cfoutput>

重新编写原始循环,看起来像这样,但它只返回base64字符串的第一次出现:

Re-wrote the original loop to look like this but it only returns the first occurrence of the base64 string:

<cfset counter = 1>
<cfset my_array =[]>
<cfoutput>
  <cfloop condition = "counter LTE 5">
    <cfset mystart = find(#string_base64_header#, #textarea_to_search#)>
    <cfset myend = find(#string_base64_ending#,#textarea_to_search#,#mystart#)>
    <cfset my64 = mid(#textarea_to_search#, (#mystart#+7), ((#myend#-7)-#mystart#))>
    <span style=font-size:8px;"> #mystart#, #myend#, #my64#</span>
    <cfset ArrayAppend(my_array, #my64#)>
    <cfset counter = counter+1>
  </cfloop>
  <cfdump var = "#my_array#">

</cfoutput>


推荐答案

有很多方法可以去关于这个,可能用正则表达式是最好的,但我无法得到这个工作的一个简单例子,或者,你可以在找到它们的时候替换字符串中的出现,并继续查找,直到没有剩余。

There are a number of ways you could go about this. Possibly with a regex would be best, though I couldn't get an easy example of this working. Alternatively, you could replace the occurrences in the string as you find them and keep looking until there are none left.

你需要做更多的工作来完成错误检查/验证等工作,但这里有个基本的例子。以下是完整的示例

You'd have to do more work than this for error checking / validation, etc, but here's a basic example. Here's the full example.

<cfset Base64Header = "base64,">
<cfset Base64Ending = '"'>

<cfset ResultsArray =[]>
<cfset ContinueSearching = true>

  <cfloop condition = " ContinueSearching eq true "><cfoutput>

    <cfset StartingIndex = find( Base64Header, SearchText)>

    <cfif StartingIndex eq 0>
        <cfset ContinueSearching = false>
        <cfcontinue/>
    </cfif>

    <cfset EndingIndex = find( Base64Ending , SearchText, StartingIndex )>

    <cfset FullOccurrence =  mid(#SearchText#, (#StartingIndex#), ((#EndingIndex#)-#StartingIndex#))>
    <cfset LocalOccurrence = mid(#SearchText#, (#StartingIndex#+7), ((#EndingIndex#-7)-#StartingIndex#))>

    <cfset ArrayAppend(ResultsArray, #LocalOccurrence#)>

    <cfset SearchText = replace(SearchText, FullOccurrence, "")>

    <cfset StartingIndex = 0>

  </cfoutput></cfloop>

  <cfdump var = "#ResultsArray#">

这篇关于Coldfusion搜索HTML&lt; textarea&gt;然后隐藏Base64字符串到服务器上的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆