Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting PHP Code to Coldfusion

Status
Not open for further replies.

forumposters

Programmer
Aug 31, 2006
61
US
I've found a script that does almost exactly what I need, but it uses PHP - I know nothing about PHP. Anyone here want to help me convert the PHP to Coldfusion? It's not a whole lot of code. Here's a demo and the source code is below the demo:

 
This looks like a simple picture upload. This is very easy to create.
[ol]
[li]Create an HTML form, with the action="" linking to a processing page (like upload_x.cfm)[/li]
[li]In upload_x.cfm, first check to see if the file field is not blank. If blank redirect user to upload form with a friendly error message). If not blank, then do a series of checks (like is the filefiled value an image and not something else -like .doc or .exe or .zip); agian, if it is then redirect user to an error page, if not move onto the next check. Common checks are:[ul square]
[li]If filefield is an image[/li]
[li]Check file size (you can either resize the image OR rediect user back to upload page with message indicating what file sizes are permitted)[/li]
[/ul]
[/li]
[li]If all checks passed, then upload image onto server. This is done via the <cfftp> tag[/li]
[li]After uploading insert into image path and image name in the dB[/li]
[li]If you want to display the image on the screen, then query the dB and display the image on the screen[/li]
[/ol]

Of course you can play around with this and come up with many clever ways, but in essence this is an easy task to accomplish in CF.

Good luck.

____________________________________
Just Imagine.
 
The hard part is to show the image thumbnail without refreshing the page or making the user click another button after they browse to and select an image. The javascript, ajax, jquery, or whatever that goes on there baffles me. This example already has the client side processind part done, but I don't understand it well enough to see how it works and I don't understand the PHP code well enough to translate it into Coldfusion.
 
Can someone convert any or all of the PHP code below to Coldfusion?

<?php
$ftmp = $_FILES['image']['tmp_name'];
$oname = $_FILES['image']['name'];
$fname = 'upload/'.$_FILES['image']['name'];
if(move_uploaded_file($ftmp, $fname)){
?>
<html><head><script>
var par = window.parent.document;
var images = par.getElementById('images');
var imgdiv = images.getElementsByTagName('div')[<?=(int)$_POST['imgnum']?>];
var image = imgdiv.getElementsByTagName('img')[0];
imgdiv.removeChild(image);
var image_new = par.createElement('img');
image_new.src = 'resize.php?pic=<?=$oname?>';
image_new.className = 'loaded';
imgdiv.appendChild(image_new);
</script></head>
</html>
<?php
exit();
}
 
there is no need to convert that piece of code.

It is moving a file from a tmp location to where it should be stored, or checking to see if it was moved.

I don't know if move_uploaded_file() is a custom function or not.

The bulk of it is javascript anyways, with a few php variables output to it.

I don't think most of this code applies as cffile moves the temp files for you when you use the action="UPLOAD" attribute / value





Kevin

Phase 1: Read the CFML Reference
Phase 2: ???
Phase 3: Profit!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top