Jump to content

rahulmehta

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

rahulmehta's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. my file is first copied to cloud and then imagethumb function is called if i upload the file greater than 1mb than image thumb is not created please suggest what is the problem ..
  2. <?php function save($path){ $input = fopen("php://input", "r"); $fp = fopen($path, "w"); while ($data = fread($input, 1024)){ fwrite($fp,$data); } fclose($fp); fclose($input); } // Get file name - eg: myphoto.jpg function getName(){ return $_GET['qqfile']; } // Get all params passed from onSubmit() function getParam($p='all'){ if ($p=='all') { return $_GET; } else { return $_GET[$p]; } } // Get file size of file function getSize(){ $headers = apache_request_headers(); return (int)$headers['Content-Length']; } // Get MIME type of file function getFileType(){ $headers = apache_request_headers(); return (string)$headers['Content-Type']; } /* Function to generate thumbnails of uploaded images * * @param string $thumbWidth Width of the thumbnail to be created * @param string $sourceUrl Location of temp file * @param string $imgType Image MIME type * @param string $bucket Bucket * @param string $cloudFront Link to Cloudfront server * @return string $thumbLink Link to generated thumbnail */ function imgThumbs($minSize, $sourceUrl, $imgType, $bucket, $cloudFront){ $s3 = new S3(awsAccessKey, awsSecretKey); $thumbId = uniqid(); $thumbId .= ".jpg"; $img = ''; if($imgType == "image/jpeg"){ $img = imagecreatefromjpeg($sourceUrl); }else if($imgType == "image/png"){ $img = imagecreatefrompng($sourceUrl); }else if($imgType == "image/gif"){ $img = imagecreatefromgif($sourceUrl); }else{ $img = imagejpeg($sourceUrl); } $width = imagesx( $img ); $height = imagesy( $img ); if($minSize == '') { $minSize = 100; $newWidth = $minSize; $newHeight = $minSize; }else{ if($width>$height){ // calculate thumbnail size $newWidth = $minSize; $newHeight = floor( $height * ( $minSize / $width ) ); }else{ // calculate thumbnail size $newWidth = floor( $width * ( $minSize / $height ) ); $newHeight =$minSize ; } } // create a new temporary image $tmp_img = imagecreatetruecolor( $newWidth, $newHeight ); // copy and resize old image into new image imagecopyresampled($tmp_img, $img, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); $path = dirname(__FILE__) . "/$thumbId"; // output the image if(imagejpeg($tmp_img, $path)){ $thumbLink = ""; // upload thumbnail to s3 if($s3->putObjectFile($path, $bucket, $thumbId, S3::ACL_PUBLIC_READ)){ $thumbLink = $cloudFront.$thumbId; imagedestroy($tmp_img); unlink($path); } return $thumbLink; break; } } //include the S3 class if (!class_exists('S3'))require_once('S3.php'); // include SimpleDB class only once if (!class_exists('SimpleDB'))require_once('sdb.php'); // Set awsAccessKey and awsSecretKey to your values require_once('config.inc.php'); //instantiate the S3 class $s3 = new S3(awsAccessKey, awsSecretKey); //instantiate the SimpleDB class $sdb = new SimpleDB(awsAccessKey, awsSecretKey); // Set temp directory where files will be written temporarily $uploaddir = 'uploads/'; // Max file size 100 MB $maxFileSize = 100 * 1024 * 1024; $thumb = ''; $status = ''; $imgWidth = ''; $imgHeight = ''; // Get file size from Apache headers $fileSize = getSize(); // Get MIME type from Apache headers $fileType = getFileType(); if ($fileSize == 0){ return array(success=>false, error=>"File is empty."); } if ($fileSize > $maxFileSize){ return array(success=>false, error=>"File is too large."); } // Put data of pathinfo() array into $pathinfo $pathinfo = pathinfo(getName()); // Get file name - eg: myphoto $filename = $pathinfo['filename']; // Get extension - eg: .jpg $ext = $pathinfo['extension']; $originalName = $filename.'.'.$ext; // Generate unique id for the current object $randName = uniqid(); // Unique file name with extension $fileTempName = $randName . '.' . $ext; // Complete temp file name and path $fullTempName = $uploaddir . $fileTempName; // Upload the file to temp directory on .net server save($fullTempName); // If images, call the function imgThumbs() to generate thumbnails if(preg_match("/^image/", $fileType)){ if(isset($_GET['profile_pic'])){ $tbnail = $_GET['avatar_width']; $avatar_url = imgThumbs($tbnail, $fullTempName, $fileType, $bucket, $cloudFront); } $tbnail = $_GET['thumb_width']; $thumb = imgThumbs($tbnail, $fullTempName, $fileType, $bucket, $cloudFront); list($imgWidth, $imgHeight) = getimagesize($fullTempName); } // Metadata for SimpleDB $contentObjectType = "upload"; $timeStamp = time(); $url = $cloudFront.$fileTempName; $on_floor = "true"; /* * An array of (name => (value [, replace])), * where replace is a boolean of whether to replace the item. * replace is optional, and defaults to false. * If value is an array, multiple values are put. */ $putAttributesRequest = array( "contentid" => array("value" => "$randName"), // unique id for EVERY object and link "content_obj_type" => array("value" => "$contentObjectType"), // whether link or file upload "file_name" => array("value" => "$fileTempName"), // unique generated filename "url" => array("value" => "$url"), //file's CDN url "original_name" => array("value" => "$originalName"), //original name of the file "file_size" => array("value" => "$fileSize"), //size of file uploaded "time_stamp" => array("value" => "$timeStamp"), //time "file_type" => array("value" => "$fileType"), //mime type of uploaded file "thumb" => array("value" => "$thumb"), //thumbnail link "avatar_url" => array("value" => "$avatar_url"), //thumbnail link "width" => array("value" => "$imgWidth"), //width of uploaded image "height" => array("value" => "$imgHeight"), //height of uploaded image "on_floor" => array("value" => "$on_floor") //by default all cObj on floor ); // Get ALL the parameter hash passed $contentObjHash = getParam(); foreach($contentObjHash as $key => $value){ $putAttributesRequest["$key"] = array("value" => "$value"); } //check whether a form was submitted if(isset($fileTempName)){ // Begin object hash here $objHash = '{'; /* Move the file to S3 * * @param mixed $fileTempName Location of temp file * @param string $bucket Bucket * @param string $newFileName Unique generated file name * @param constant ACL * @param array() Dont worry about this * @param string $fileType MIME type of file * @return boolean */ if(!$s3->putObjectFile($fullTempName, $bucket, $fileTempName, S3::ACL_PUBLIC_READ, array(), $fileType)) { $status = 'false'; $objHash .= "success : ".json_encode($status)."}"; // End object hash here id S3 error echo $objHash; return; } /** * Create or update attributes * * @param string $domain Domain * @param string $randName Unique generated file name * @param array $putAttributesRequest See up for more info * @return boolean */ if($sdb->putAttributes($domain, $randName, $putAttributesRequest)){ $status = 'true'; unlink($fullTempName); }else{ $status = 'false'; $objHash .= "'SimpleDB_error' : ".json_encode($sdb->ErrorCode).","; } foreach($putAttributesRequest as $key => $value){ $objHash .= json_encode($key). " : " . json_encode($value["value"]) .", "; } $objHash .= "'success' : ".$status."}"; // End object hash after SimpleDB transaction echo $objHash; } ?>
  3. in my php.ini Maximum size of POST data that PHP will accept. is post_max_size = 20M is these are ok ? or should i change to something else ?
  4. i am uploading image to s3 server and by php i am making a copy of that image on server , if i upload an image of 2.3 mb than the width of image is not coming but if i upload less size image like 26kb than it is showing the width of image so it is able to create the copy . here is my code of php : $s3 = new S3(awsAccessKey, awsSecretKey); $thumbId = uniqid(); $thumbId .= ".jpg"; $img = ''; if($imgType == "image/jpeg"){ $img = imagecreatefromjpeg($sourceUrl); }else if($imgType == "image/png"){ $img = imagecreatefrompng($sourceUrl); }else if($imgType == "image/gif"){ $img = imagecreatefromgif($sourceUrl); }else{ $img = imagejpeg($sourceUrl); } echo $width = imagesx( $img ); echo $height = imagesy( $img ); please tell me what is the problem with size of image.. regards rahul
  5. ^^^ you need to turn that setting ON. ok thanks its working regards rahul
  6. m not getting what you are saying why we need to check session exist or not ....
  7. hii , m using extjs and php in my login form on index.php and post action is checklogin.php if successful login than i return to main.php and during action of login form in checklogin.php m setting the session variable of userid which is m not getting on main.php and every time i refresh the page it generate new session id . why this happening.. my session variable in php.ini are session Session Support enabled Registered save handlers files user Registered serializer handlers php php_binary wddx Directive Local Value Master Value session.auto_start Off Off session.bug_compat_42 On On session.bug_compat_warn On On session.cache_expire 180 180 session.cache_limiter nocache nocache session.cookie_domain no value no value session.cookie_httponly Off Off session.cookie_lifetime 0 0 session.cookie_path / / session.cookie_secure Off Off session.entropy_file no value no value session.entropy_length 0 0 session.gc_divisor 1000 1000 session.gc_maxlifetime 1440 1440 session.gc_probability 1 1 session.hash_bits_per_character 5 5 session.hash_function 0 0 session.name PHPSESSID PHPSESSID session.referer_check no value no value session.save_handler files files session.save_path c:/wamp/tmp c:/wamp/tmp session.serialize_handler php php session.use_cookies Off Off session.use_only_cookies On On session.use_trans_sid 0 0 please help thank regards rahul
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.