coldfusion上传图片

<cfprocessingdirective pageencoding="utf-8">
<cfif isDefined("form.uploadImage")>
  <CFSET thisPath = ExpandPath("*.*")>
  <CFSET thisDirectory = GetDirectoryFromPath("request.siteurl")>
  <cfset filePath = expandPath("#thisDirectory#\shop\upload\")>
  <cfif not directoryExists(filePath)>
    <cfdirectory action="create" directory="#filePath#">
  </cfif>
  <cftry>
    <cffile action="upload" filefield="upimg" destination="#filePath##imgPath#"  accept=  "image/bmp,image/png,image/gif,image/jpeg,image/jpg,image/x-png,image/pjpeg"  nameconflict="overwrite">
    <cfcatch>
      <cfset tipmsg="图片格式不正确,只能是jpg、gif和bmp格式图片的才能上传">
    </cfcatch>
  </cftry>
  <cfquery name="updateShopimg" datasource="#request.dsn#">
    update  shop_info
     set images=<cfqueryparam cfsqltype="cf_sql_varchar" value="shop/upload/#imgPath#">
where shop_id=<cfqueryparam cfsqltype="cf_sql_varchar" value="#form.uplod_shopId#">
  </cfquery>
  <cflocation url="#request.siteurl#index.cfm/action/shop.detail/shopid/#url.shopid#" addtoken="no">
</cfif>






<div id="divUploadContent">
  <div id="shafridBox" width="200">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="19" height="19" class="l_top_angle">&nbsp;</td>
        <td class="top_ct">&nbsp;</td>
        <td width="19" height="19"  class="r_top_angle">&nbsp;</td>
      </tr>
      <tr>
     
      <td width="19" class="l_ct">&nbsp;</td>
      <td height="30" align="center" valign="middle" style="background-color:#FFFFFF;">
      <div class="shafridBoxCt" style="background-color:#FFFFFF;">
     
      <div class="shafridBoxCtTl"><span class="fl font14 heavyGray boldFont">上传图片</span><img name="closeModal"  style="cursor:pointer" onclick="$.modal.close();" class="fr" src="/images/wrong_pic.gif" /></div>
      <div class="">
      <form method="post" enctype="multipart/form-data" action='uploadimage.cfm'>
      <table width="70%">
        <tr>
          <td align="left"><input name="upimg" type="file" value="浏览" accept="jpg|gif">
          </td>
        </tr>
        <tr>
          <td align="center"><input type="submit"  value="上传"  name="uploadImage"></td>
        </tr>
      </table>
      </div>
      </td>     
      <td width="19" class="r_ct">&nbsp;</td>
      </tr>     
      <tr>
        <td width="19" height="19"  class="l_bt_angle">&nbsp;</td>
        <td class="bt_ct">&nbsp;</td>
        <td width="19" height="19"  class="r_bt_angle">&nbsp;</td>
      </tr>
    </table>
    <input type="hidden" name="imgPath"  id="imgPath" value="<cfoutput>#request.ccid#</cfoutput>.gif">
    <input type="hidden" name="uplod_shopId"  id="uplod_shopId" value="<cfoutput>#url.shopid#</cfoutput>">
    </form>
  </div>
</div>

你可能感兴趣的:(ColdFusion)