我有以下代码将图像上传到 rackspace cdn 帐户。
error_reporting(E_ALL);
ini_set('display_errors', 1);
// include the API
require("cloudfiles.php") ;
// cloud info
$username = ''; // username
$key ='' ; // api key
$container = ''; // container name
ob_start();
$localfile = $_FILES['media']['tmp_name'];
$filename = $_FILES['media']['name'];
ob_flush();
// 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->create_container($container);
// store file information
ob_flush();
// upload file to Rackspace
$object = $container->create_object($filename);
$object->load_from_filename($localfile);
$uri = $container->make_public();
//print "Your URL is: " . $object->public_uri();
$imagePageUrl = $object->public_uri();
//echo '<mediaurl>' . $imagePageUrl . '</mediaurl>';
ob_end_flush();
//echo '<mediaurl>' . $imagePageUrl . '</mediaurl>';
echo '<mediaurl>http://url.com/'.$filename.'</mediaurl>';
因此,每次我上传图像时,例如 image.jpg,它都会覆盖容器中的前一个 image.jpg。我想阻止这种情况。即使文件名相同,有没有办法将文件名转换为随机名称,字符然后上传?
帮助请。