There are no other dependencies.
<?php
$sc = new SuperContainer('http://server.mycompany.com:8020/SuperContainer/Files');
?>
<?php
$sc->upload('uploads/12345', '/path/to/my/local-file.txt');
?>
<?php
$infoArray = $sc->getInfo('uploads/12345');
$fileName = $infoArray['name'];
$fileSize = $infoArray['size'];
$uploadDate = $infoArray['date'];
?>
<?php
$localPath = $sc->download('uploads/12345', '/tmp');
?>
<?php
$sc->delete('uploads/12345');
?>
To handle file uploads in PHP, move the uploaded file using the move_uploaded_file
function, then the upload
function of SuperContainer.
The following example illustrates handling a file upload, and better error handling.
<?php
$SC_BASE_URL = 'http://server.mycompany.com:8020/SuperContainer/Files';
$sc = new SuperContainer($SC_BASE_URL);
if ($sc->getError()) die('Could not connect to SuperContainer server: ' . $sc->getError());
$uploadedFile = sys_get_temp_dir() . '/' . $_FILES['upload']['name'];
move_uploaded_file($_FILES['upload']['tmp_name'], $uploadedFile)
or die("Could not move uploaded file to $uploadedFile");
$folderPath = 'uploads/12345';
$sc->upload($folderPath, $uploadedFile)
or die("Could not upload $uploadedFile to $folderPath: " . $sc->getError());
?>
Note that values cannot be returned from a constructor, therefore it is difficult to validate the return value.
To verify that the SuperContainer
object was created correctly, you should call getError()
immediately after creating the new object.
$baseUrl -
The Base URL of your SuperContainer server, e.g. http://server.mycompany.com:8020/SuperContainer/Files
$user -
Optional username, only required if your SuperContainer server is password protected$password -
Optional password, only required if your SuperContainer server is password protectedtrue
if the upload was successful, false if not.$folderPath -
The unique identifier for a supercontainer file.$data -
local path to the file to upload.false
if the download failed, or ''
if there was no file to download at the specified folderPath
.
Note: If $destination
is a directory, the downloaded file will be given the same name it had on the SuperContainer server. If $destination
is not a directory, the file will be downloaded to $destination
without altering the path at all. Note that the parent directory must exist for this operation to complete successfully.
$folderPath -
The unique identifier for the supercontainer file to download$destination -
The local destination path to download the file tostrtotime()
to convert this to a timestamp)
If there is no file at the given folderPath
, an empty array is returned. However, calling getError
will return an empty string.
$folderPath -
The unique identifier for the supercontainer file to downloadtrue
if the delete operation was successful, or there was no file to delete. Otherwise, returns false
.$folderPath -
The unique identifier for the supercontainer file to download