I did one project, I using zend library "Gdata". I had upload demo 2 difference hosting.
1. hosting kloxo
- That code upload very slow, slow.... Sometimes do not working.
2. hosting CPannel
- That code upload very fast.
Someone know that? Help me?
My code:
<?php
define('DIR', dirname(__FILE__));
$tempfolder = DIR . '/temp/';
$sitename = 'buybingo.net';
$isWatermark = ($_REQUEST['watermark'] == 'yes') ? true : false;
if($_FILES['Filedata']){
$error = false;
$file = $_FILES['Filedata'];
$filePath = $tempfolder . $sitename . time().'.'.end(explode('.',basename($file['name'])));
if (!isset($file) || !is_uploaded_file($file['tmp_name'])) {
$error = 'Invalid Upload';
}
if (!$error && $file['size'] > 2 * 1024 * 1024)
{
$error = 'Please upload only files smaller than 2Mb!';
}
if (!$error && !($size = @getimagesize($file['tmp_name']) ) )
{
$error = 'Please upload only images, no other files are supported.';
}
if (!$error && !in_array($size[2], array(1, 2, 3, 7, 8) ) )
{
$error = 'Please upload only images of type JPEG, GIF or PNG.';
}
if($error) die('image='.$error);
move_uploaded_file($file['tmp_name'], $filePath);
$resizes = array(
1 => 100,
2 => 150,
3 => 320,
4 => 640,
5 => 800,
6 => 1024
);
$resize = intval($_REQUEST['resize']);
if(in_array($resize, array_keys($resizes)))
{
if(!file_exists(DIR. '/inc/phpThumb/ThumbLib.inc.php'))
{
throw new Exception('Missing file '.DIR. '/inc/phpThumb/ThumbLib.inc.php');
}
else
{
require_once(DIR. '/inc/phpThumb/ThumbLib.inc.php');
$thumb = PhpThumbFactory::create($filePath);
$thumb->resize($resizes[$resize], 0);
$thumb->save($filePath);
}
}
if($isWatermark && ($size[0] > 150) && ($size[1] > 35)){
$watermark_path = DIR . '/logo1.png';
$watermark_id = imagecreatefrompng($watermark_path);
imagealphablending($watermark_id, false);
imagesavealpha($watermark_id, true);
$info_img = getimagesize($filePath);
$info_wtm = getimagesize($watermark_path);
$fileType = strtolower($info_img['mime']);
$image_w = $info_img[0];
$image_h = $info_img[1];
$watermark_w = $info_wtm[0];
$watermark_h = $info_wtm[1];
$is_gif = false;
switch($fileType)
{
case 'image/gif': $is_gif = true;break;
case 'image/png': $image_id = imagecreatefrompng($filePath); break;
default: $image_id = imagecreatefromjpeg($filePath); break;
}
if(!$is_gif){
$dest_x = ($image_w - $watermark_w);
$dest_y = ($image_h - $watermark_h);
imagecopy($image_id, $watermark_id, $dest_x, $dest_y, 0, 0, $watermark_w, $watermark_h);
switch($fileType)
{
case 'image/png': imagepng ($image_id, $filePath); break;
default: imagejpeg($image_id, $filePath); break;
}
imagedestroy($image_id);
imagedestroy($watermark_id);
}
}
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Photos');
Zend_Loader::loadClass('Zend_Http_Client');
$serviceName = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
$user = "xxx@gmail.com";
$pass = "xxxx";
$albumId = "582879xxxxxx";
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $serviceName);
$gp = new Zend_Gdata_Photos($client, "Google-DevelopersGuide-1.0");
$username = "default";
$filename = $filePath;
$photoName = preg_replace('/\s+/','_',basename($file['name']));
$photoCaption = $photoName;
$photoTags = "";
$fd = $gp->newMediaFileSource($filename);
$fd->setContentType(strtolower($size['mime']));
$photoEntry = $gp->newPhotoEntry();
$photoEntry->setMediaSource($fd);
$photoEntry->setTitle($gp->newTitle($photoName));
$photoEntry->setSummary($gp->newSummary($photoCaption));
$keywords = new Zend_Gdata_Media_Extension_MediaKeywords();
$keywords->setText($photoTags);
$photoEntry->mediaGroup = new Zend_Gdata_Media_Extension_MediaGroup();
$photoEntry->mediaGroup->keywords = $keywords;
$albumQuery = $gp->newAlbumQuery();
$albumQuery->setUser($username);
$albumQuery->setAlbumId($albumId);
$insertedEntry = $gp->insertPhotoEntry($photoEntry, $albumQuery->getQueryUrl());
$contentUrl = "";
if ($insertedEntry->getMediaGroup()->getContent() != null) {
$mediaContentArray = $insertedEntry->getMediaGroup()->getContent();
$contentUrl = $mediaContentArray[0]->getUrl();
}
if(file_exists($filePath))
{
unlink($filePath);
}
if($contentUrl)
{
$host = explode('/',$contentUrl);
$host[6] = $host[6].'/s0';
$contentUrl = 'https:/'.$host[1].'/'.$host[2].'/'.$host[3].'/'.$host[4].'/'.$host[5].'/'.$host[6].'/'.$host[7];
echo 'image=' . $contentUrl;
}
else echo 'image=Upload failed.';
}
if($_POST['url']){
echo 'Nothing';
}
?>