This topic is locked

Upload File to Cloudfiles

4/29/2010 4:23:07 PM
PHPRunner General questions
G
greener author

Hi,

we are using Rackspace Cloudfiles (similar to Amazon S3) to store images. I'd like the ability to upload the file into our cloudfiles directly from our PHP Runner 5.2 application versus storing on our server. This is how we do it with a regular html/php script:
The html page:

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

</head>
<body>

<form action="upload.php" enctype="multipart/form-data" method="POST">

File: <input name="upload" type="file" />



<input name="submit" type="submit" value="Upload To Rackspace!" />

</form>

</body>

</html>


and this is the upload.php file

<?php

// include the API

require('cloudfiles/cloudfiles.php');



// cloud info

$username = "myusername"; // username

$key = "my_key"; // api key



// Connect to Rackspace

$auth = new CF_Authentication($username, $key);

$auth->authenticate();

$conn = new CF_Connection($auth);



// Get the container we want to use

$container = $conn->get_container('container');



// store file information

$localfile = $_FILES['upload']['tmp_name'];

$filename = $_FILES['upload']['name'];



// upload file to Rackspace

$object = $container->create_object($filename);

$object->load_from_filename($localfile);

?>


How would we do this?
thank you in advance... Randall

Sergey Kornilov admin 4/29/2010

I think you can use your code in BeforeAdd/BeforeEdit events almost as is.
The only thing you need need to change is the name of the form field in the following section:

$localfile = $_FILES['upload']['tmp_name'];

$filename = $_FILES['upload']['name'];


Replace field name in bold with the actual field name from the database:

$localfile = $FILES['fileFieldName']['tmp_name'];

$filename = $FILES['fileFieldName']['name'];