Can ColdFusion upload a file to a different domain?

SiobhanElara
SiobhanElara used Ask the Experts™
on
We have a client that has three domains for three different properties (we'll call them a.com, b.com, and c.com), but wants to administer all the content through one main admin on a.com.

I'm not having a problem with information that's contained in databases, especially since all the domains are hosted on the same server. My problem is with the extremely simple photo galleries on each domain (and by "simple" I mean the images names are merely retrieved with cfdirectory.)

Is there a way to upload an image from a.com/admin to b.com/images/gallery? I've never had to do anything like this before and can't seem to even retrieve the directory contents of b.com/images/gallery from a.com. Would all this require cfftp instead?

Thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

It depends on the server.   I host myself and have open access between all my directories.  I could do this easily.   However, if you have a third party host and have three seperate accounts, then it would likely not be allowed for security.   If you have one account, with multiple domains, then ask your host if you can access the different directories.

Otherwise, then do as you suggest and use CFHTTP to pull the file over...
Staff IT Engineer
Commented:
If you have control over BOTH the domains and servers, you can use CFHTTP to upload file from one server to another


--- CFHTTP CODE ON a.com ---
<cfhttp url="http://b.com/images/gallery/galleryCfhttp.cfm" method="post">  
              <cfhttpparam name="file1" type="file" file="YOURFILEPATH ON a.com" mimetype="image/jpeg" />  
              <cfhttpparam name="BecauseTheFileIsCorruptedWithoutThisField" type="formfield" value="" />  
   </cfhttp>


--- Then ON B.COM, you can have code like - galleryCfhttp.cfm ----

<cfif structKeyExists(FORM, "File1")>
   <cfset UploadPath = 'Path On B.com /images/gallery/' />
    <cffile action="upload" destination="#UploadPath#" nameconflict="overwrite" />  
</cfif>
 
You don't actually need to have control over both websites, you can pull images and files from any website.

Here is an example using CFTTP.  No parameters are needed.

After pulling the file over, this checks status and tests for existance.


<cfset  variables.imageURL = "http://google.com/logo.jpg">
 <cfset  variables.TempFile  = "c:\images\logo.jpg">

 <cfhttp url="#variables.imageURL#" path="#getDirectoryFromPath(variables.TempFile)#" file="#getFileFromPath(variables.TempFile)#" method="GET"></cfhttp>

 <cfif val(cfhttp.statusCode) is not 200>
    <cfthrow message="#cfhttp.statusCode#" detail="Download failed: #cfhttp.statusCode#" type="myError">	
 </cfif>	
 <cfif NOT fileExists(variables.TempFile)>
   <cfthrow message="File Not Downloaded" detail="Form file was not found in temp directory after download" type="myError">
 </cfif>

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial