Hello how can i include url function in photo
function photoUpload($file)
{
$messages = '';
$t = [];
$i = 0;
try {
$input = array(
'files' => $file,
'type' => Input::get('type'),
'max' => 1,
);
$files = array($input['files']);
$image = \Image::make($file->getRealPath());
$bigpath = public_path() . '/pictures/contentPhoto/big/';
$mediumpath = public_path() . '/pictures/contentPhoto/medium/';
$thumbpath = public_path() . '/pictures/contentPhoto/thumb/';
$maxFile = $input['max'];
$image->backup();
$rules = array('file' => 'max:50000|mimes:png,gif,jpeg,jpg');
if( !is_array($files) )
return ['status'=>false, 'msg'=> 'Bir problem var!' ];
if(count($files)>$maxFile)
return ['status'=>false, 'msg'=> 'En az bir fotoğraf gerekli!' ];
$status = array();
foreach ($files as $file) {
$isim = md5(uniqid('', true));
$t[]['org_name'] = $file->getClientOriginalName();
$t[$i]['extension'] = $file->getClientOriginalExtension();
$t[$i]['remote_name'] = $isim . '.' . $t[$i]['extension'];
$t[$i]['path'] = $thumbpath;
$t[$i]['remote_name'] = $isim . '.' . $file->getClientOriginalExtension();
$validator = Validator::make(array('file' => $file), $rules, [], ['file' => $file->getClientOriginalName()]);
if ($validator->passes()) {
$t[$i]['info'] = '<li>' . $file->getClientOriginalName() . ' bu fotoğraf yüklendi.' . '</li>';
$t[$i]['result'] = true;
$t[$i]['remote_full_name'] = Config::get('app.url') . '' . Config::get('app.pictures_db') . '/contentPhoto/thumb/' . $t[$i]['remote_name'];
$status[] = 1;
if (!file_exists(public_path().'/pictures/contentPhoto/')) {
mkdir(public_path().'/pictures/contentPhoto/', 0777, true);
}
$post_photo=$_FILES['files']['name'];
$post_photo_tmp=$_FILES['files']['tmp_name'];
$ext = pathinfo($post_photo, PATHINFO_EXTENSION); // getting image extension
list($width_min,$height_min)=getimagesize($post_photo_tmp); // fetching original image width and height
$ratio = $width_min / $height_min;
// Big Size
$newwidth_min=700; // set compressing image width
$newheight_min=($height_min / $width_min) * $newwidth_min; // equation for compressed image height
$big = $image->resize($newwidth_min,$newheight_min);
$big->sharpen(18)->save($bigpath.$t[$i]['remote_name'],60);
$big->reset();
if($ratio < 1) {
$t[$i]['ratio'] = false;
// Medium Size
$newwidth_min=320; // set compressing image width
$newheight_min=($height_min / $width_min) * $newwidth_min; // equation for compressed image height
$medium = $image->resize($newwidth_min,$newheight_min);
$medium->sharpen(8)->save($mediumpath.$t[$i]['remote_name'],60);
$medium->reset();
// Thumb Size
$newwidth_min=220; // set compressing image width
$newheight_min=($height_min / $width_min) * $newwidth_min; // equation for compressed image height
$thumb = $image->resize($newwidth_min,$newheight_min);
$thumb->sharpen(8)->save($thumbpath.$t[$i]['remote_name'],60);
$thumb->reset();
} else {
$t[$i]['ratio'] = true;
// Medium Size
$targetHeight= 320;
$targetWidth = 240;
$imgWidth = $image->getWidth();
$imgHeight = $image->getHeight();
$verticalRatio = $targetHeight / $imgWidth;
$horizontalRatio = $targetWidth / $imgHeight;
$imgAvg = min($verticalRatio,$horizontalRatio);
$newHeight = $imgHeight * $imgAvg;
$newWidth = $imgWidth * $imgAvg;
$medium = $image->resize($newWidth,$newHeight);
$medium->fit(320,170)->sharpen(8)->save($mediumpath.$t[$i]['remote_name'],60);
$medium->reset();
// Thumb Size
$targetHeight= 320;
$targetWidth = 240;
$imgWidth = $image->getWidth();
$imgHeight = $image->getHeight();
$verticalRatio = $targetHeight / $imgWidth;
$horizontalRatio = $targetWidth / $imgHeight;
$imgAvg = min($verticalRatio,$horizontalRatio);
$newHeight = $imgHeight * $imgAvg;
$newWidth = $imgWidth * $imgAvg;
$thumb = $image->resize($newWidth,$newHeight);
$thumb->fit(320,170)->sharpen(8)->save($thumbpath.$t[$i]['remote_name'],60);
$thumb->reset();
}
$insertDb = DBDosya::insertPicture($file->getClientOriginalName(), $isim.'.'.$file->getClientOriginalExtension(), '' . Config::get('app.pictures') . '/', '.'.$file->getClientOriginalExtension() );
$t[$i]['id'] = $insertDb;
} else {
$t[$i]['result'] = false;
$mesajlar = $validator->messages();
$htmlMesaj = '';
foreach ($mesajlar->all('<li>:message</li>') as $mesaj) {
$htmlMesaj .= $mesaj;
}
$t[$i]['info'] = $htmlMesaj;
}
$messages .= $t[$i]['info'];
$i++;
}
$status = in_array(1, $status);
} catch (Exception $e) {
return ['status' => false, 'msg' => $messages . '<li>' . $e->getMessage() . '</li>',];
}
return ['status' => $status, 'msg' => $messages, 'data' => $t[0]];
}
It works properly in the files that come with this file.
But I get getRealPath () error when I get photo with url.
How can I handle the photo from the URL with this function
Related
Laravel Newbie here, would like to ask how to upload multiple images one by one. Multiple images work in one selection but putting images one by one to upload doesn't work and the first image only appears after submitting. Please help.
CONTROLLER
if (\Input::file('photos')) {
$base_path =
dirname(__FILE__) . "/../../../../uploads/img/gallery/" . $add->id . "/";
ini_set('gd.jpeg_ignore_warning', 1);
//get last uploaded file name
$files = (\Input::file('photos'));
$list_image = $temp = explode(",", $request->list_image);
foreach ($files as $key => $value) {
if (!is_null($value)) {
$temp = explode(".", $value->getClientOriginalName());
$newfilename = $value->getClientOriginalName();
if (!file_exists($base_path)) {
mkdir($base_path);
chmod($base_path, 0777);
}
$key = array_search($newfilename, $list_image);
if ($key == 0) {
$newfilename = $add->id . '_primary' . '.' . end($temp);
} else {
$newfilename = chr(64 + $key) . '_' . $newfilename;
}
$image = \Image::make($value);
// perform orientation using intervention
$image->orientate();
$new_width = $image->width();
$new_height = $image->height();
if ($new_width > 800) {
$percent = 0.7;
$new_width = $new_width * $percent;
$new_height = $new_height * $percent;
}
// resize image to fixed size
$image->resize($new_width, $new_height);
// create a new Image instance for inserting
$watermark = \Image::make(
public_path() . '/assets/img/icons/watermark.png',
);
// insert watermark at bottom-right corner with 10px offset
$image->insert(
public_path() . '/assets/img/icons/watermark.png',
'bottom-right',
10,
10,
);
$image->save($base_path . $newfilename);
}
}
}
You can do something like this.
$list_image = $temp = explode(",", $request->list_image);
if($request->hasfile('photos'))
{
$destinationPath = public_path('uploads/img/gallery/'. $add->id.'/');
foreach($request->file('photos') as $k => $file)
{
$temp = explode(".", $file->getClientOriginalName());
$newfilename = $file->getClientOriginalName();
$key = array_search($newfilename, $list_image);
if ($key == 0) {
$newfilename = $add->id . '_primary' . '.' . end($temp);
} else {
$newfilename = chr(64 + $key) . '_' . $newfilename;
}
$name = $newfilename.'.'.$file->getClientOriginalExtension();
File::makeDirectory($destinationPath, $mode = 0777, true, true);
$file->move($destinationPath, $name);
$tdestinationPath = public_path('uploads/img/gallery/thumb'. $add->id.'/');
try {
$img = Image::make($file->getRealPath());
$img->resize(50, 50, function ($constraint) {
$constraint->aspectRatio();
})->save($tdestinationPath.'/'.$name);
$img->destroy();
} catch (Exception $e) {
$response_data=array('images'=>"",'success'=>0,'message'=>$e->getMessage());
}
$image_arr[] = $name;
}
$uploaded_img = implode(',',$image_arr);
if(!empty($hidden_property_img)){
$uploaded_img = $hidden_property_img.','.$uploaded_img;
}
$data['images'] = $uploaded_img;
}
I would like to loop through multiple file uploads and the add them to my json
This is what I currently have for one upload:
$file_prefix = md5_file($tmp_file);
$file_name = $file_prefix . "_" . rand(1000, 99999) . "_{$session_check_data['id']}".".jpg";
$target_file = $vehicle_image_folder . "/".$file_name;
list($width, $height, $type, $attr) = getimagesize($tmp_file);
$image = new \Gumlet\ImageResize($tmp_file);
if($width > 1200) {
$image->resizeToWidth(1200);
}
$image->save($target_file, IMAGETYPE_JPEG);
if ($this->request->get('upload_thumb')) {
$thumbnail_file = $vehicle_image_folder . "/thumb_".$file_name;
$this->app['monolog']->info("thumbs required");
$image = new \Gumlet\ImageResize($target_file);
$image->resizeToWidth(400);
$image->save($thumbnail_file, IMAGETYPE_JPEG);
}
Here is what I attempted to do:
$files = array();
$l = 3;
foreach ($tmp_file as $k => $l) {
$file_prefix = md5_file($k);
foreach ($l as $i => $v) {
if (!array_key_exists($i, $files))
$files[$i] = array();
$files[$i][$k] = $v;
}
}
$counter = 1;
foreach ($files as $file) {
$count = $counter++;
$file_name = $file_prefix . "_" . rand(1000, 99999) . "_{$session_check_data['id']}".".jpg";
$target_file = $vehicle_image_folder . "/".$file_name;
list($width, $height, $type, $attr) = getimagesize($file);
$image = new \Gumlet\ImageResize($file);
if ($width > 1200) {
$image->resizeToWidth(1200);
}
$image->save($target_file, IMAGETYPE_JPEG);
if ($this->request->get('upload_thumb')) {
$thumbnail_file = $vehicle_image_folder . "/thumb_" . $file_name;
$this->app['monolog']->info("thumbs required");
$image = new \Gumlet\ImageResize($target_file);
$image->resizeToWidth(400);
$image->save($thumbnail_file, IMAGETYPE_JPEG);
}
}
then I would like to return the 3 images in my JSON in the loc, maybe loc1, loc2, loc3?:
return $this->app->json(['success' => 1, 'info' => 'uploaded', 'loc' => $file_name]);
I would like to be able to show the 3 images that have been uploaded
I'm new to programming and require some help regarding the below issue.
I have the below script that I guess controls the upload of the image.
Is there any easy way to add a autoresizer of the image to 1024x768?
public function index()
{
$validator = Validator::make(Input::all(), [
'image' => 'required|image|max:' . (1024 * 3),
]);
if ($validator->fails()) {
$messages = $validator->messages();
echo json_encode([
'return' => 'error',
'message' => $messages->first('image')
]);
} else {
$originalName = Input::file('image')->getClientOriginalName();
$extension = Input::file('image')->getClientOriginalExtension();
$size = Input::file('image')->getSize();
$type = (Auth::check()) ? Auth::user()->default_image_privacy : 'public';
$adult = Input::has('adult') ? Input::get('adult') : 0;
$adult = ($adult != 1) ? 0 : 1;
$status = (Settings::get('auto_approve_images') == 1) ? 'active' : 'pending';
$image = new Image;
$image->user_id = (Auth::check()) ? Auth::user()->id : 0;
$image->file_name = $originalName;
$image->file_extn = $extension;
$image->file_size = $size;
$image->status = $status;
$image->type = $type;
$image->adult = $adult;
$image->ip = Net::getIP();
$image->save();
$imageFolder = floor($image->id / 1000) + 1;
$imageFolder = md5($imageFolder);
$imageFolder = substr($imageFolder, 1, 10);
$imageFolder = trim($imageFolder);
$image->folder = $imageFolder;
$image->save();
$destinationPath = public_path('uploads/' . $imageFolder);
$fileName = $image->id . '.' . $extension;
Input::file('image')->move($destinationPath, $fileName);
$destinationPathThumb = public_path('thumb/' . $imageFolder);
if (! File::isDirectory($destinationPathThumb)) {
File::makeDirectory($destinationPathThumb, 0755, true);
}
$fileNameThumb = $image->id . '.' . $extension;
$thumbWidth = (int) Settings::get('thumb_width');
$thumbWidth = ($thumbWidth < 80) ? 100 : $thumbWidth;
$thumbHeight = (int) Settings::get('thumb_height');
$thumbHeight = ($thumbHeight < 80) ? 100 : $thumbHeight;
Thumb::create($destinationPath . '/' . $fileName, $destinationPathThumb . '/' . $fileNameThumb, $thumbWidth, $thumbHeight);
$fileNameMed = $image->id . '_md.' . $extension;
$medWidth = 700;
$medHeight = 600;
Thumb::create($destinationPath . '/' . $fileName, $destinationPathThumb . '/' . $fileNameMed, $medWidth, $medHeight);
echo json_encode([
'return' => 'success',
'imageUid' => $image->id
]);
}
exit();
}
public function link()
{
$validator = Validator::make(Input::all(), [
'url' => 'required|url',
]);
if ($validator->fails()) {
return Redirect::back()->withErrors($validator);
} else {
$originalName = basename(Input::get('url'));
$nameSplit = explode('.', $originalName);
$extension = $nameSplit[count($nameSplit) - 1];
if (! in_array($extension, ['jpeg', 'jpg', 'png', 'bmp', 'gif'])) {
return Redirect::back()->withErrors($validator);
}
$type = (Auth::check()) ? Auth::user()->default_image_privacy : 'public';
$adult = Input::has('adult') ? Input::get('adult') : 0;
$adult = ($adult != 1) ? 0 : 1;
$image = new Image;
$image->user_id = (Auth::check()) ? Auth::user()->id : 0;
$image->file_name = $originalName;
$image->file_extn = $extension;
$image->status = 'active';
$image->type = $type;
$image->adult = $adult;
$image->ip = Net::getIP();
$image->save();
$imageFolder = floor($image->id / 1000) + 1;
$imageFolder = md5($imageFolder);
$imageFolder = substr($imageFolder, 1, 10);
$imageFolder = trim($imageFolder);
$image->folder = $imageFolder;
$image->save();
$destinationPath = public_path('uploads/' . $imageFolder);
$fileName = $image->id . '.' . $extension;
File::copy(Input::get('url'), $destinationPath . '/' . $fileName);
$size = File::size($destinationPath . '/' . $fileName);
$image->file_size = $size;
$image->save();
$destinationPathThumb = public_path('thumb/' . $imageFolder);
if (! File::isDirectory($destinationPathThumb)) {
File::makeDirectory($destinationPathThumb, 0755, true);
}
$fileNameThumb = $image->id . '.' . $extension;
$thumbWidth = (int) Settings::get('thumb_width');
$thumbWidth = ($thumbWidth < 80) ? 100 : $thumbWidth;
$thumbHeight = (int) Settings::get('thumb_height');
$thumbHeight = ($thumbHeight < 80) ? 100 : $thumbHeight;
Thumb::create($destinationPath . '/' . $fileName, $destinationPathThumb . '/' . $fileNameThumb, $thumbWidth, $thumbHeight);
$fileNameMed = $image->id . '_md.' . $extension;
$medWidth = 700;
$medHeight = 600;
Thumb::create($destinationPath . '/' . $fileName, $destinationPathThumb . '/' . $fileNameMed, $medWidth, $medHeight);
return Redirect::to('/upload/success?id=' . $image->id);
}
}
public function success()
{
if (! Input::has('id')) {
return Redirect::to('/');
}
$imageIdArr = explode(',', Input::get('id'));
$imageIdArr = array_where($imageIdArr, function($key, $value)
{
return is_numeric($value);
});
$imageIdArr = array_unique($imageIdArr);
if (empty($imageIdArr)) {
return Redirect::to('/');
}
$imagesInfo = Image::whereIn('id', $imageIdArr)->get();
return View::make('upload.success', [
'imagesInfo' => $imagesInfo,
]);
}
You can resize the image with some fileuploader in the client side, you also can use server side tools such as imagemagic with command like this:
`convert $original_path -resize '1024x768^' -gravity Center -crop '1024x768+0+0' $resized_path`;
I'm trying to crop an image when it has been uploaded. So far I've only managed to resize it but if an image is a rectangular shape then the image is squashed which doesn't look nice. I'm trying to get coding that I can use with the function that I currently have to resize. The ones that I'm seeing I have to change my function and I'm hoping not to do that.
Here is my function
function createThumbnail($filename) {
global $_SITE_FOLDER;
//require 'config.php';
$final_width_of_image = 82;
$height = 85;
$path_to_image_directory = $_SITE_FOLDER.'portfolio_images/';
$path_to_thumbs_directory = $_SITE_FOLDER.'portfolio_images/thumbs/';
if(preg_match('/[.](jpg)$/', $filename)) {
$im = imagecreatefromjpeg($path_to_image_directory . $filename);
} else if (preg_match('/[.](gif)$/', $filename)) {
$im = imagecreatefromgif($path_to_image_directory . $filename);
} else if (preg_match('/[.](png)$/', $filename)) {
$im = imagecreatefrompng($path_to_image_directory . $filename);
}
$ox = imagesx($im);
$oy = imagesy($im);
$nx = $final_width_of_image;
$ny = floor($oy * ($final_width_of_image / $ox));
//$ny = $height;
$nm = imagecreatetruecolor($nx, $ny);
imagecopyresized($nm, $im, 0,0,0,0,$nx,$ny,$ox,$oy);
if(!file_exists($path_to_thumbs_directory)) {
if(!mkdir($path_to_thumbs_directory)) {
die("There was a problem. Please try again!");
}
}
imagejpeg($nm, $path_to_thumbs_directory . $filename);
$tn = '<img src="' . $path_to_thumbs_directory . $filename . '" alt="image" />';
$tn .= '<br />Congratulations. Your file has been successfully uploaded, and a thumbnail has been created.';
echo $tn;
}
Here is my function.
<?php
function crop($file_input, $file_output, $crop = 'square',$percent = false) {
list($w_i, $h_i, $type) = getimagesize($file_input);
if (!$w_i || !$h_i) {
echo 'Unable to get the length and width of the image';
return;
}
$types = array('','gif','jpeg','png');
$ext = $types[$type];
if ($ext) {
$func = 'imagecreatefrom'.$ext;
$img = $func($file_input);
} else {
echo 'Incorrect file format';
return;
}
if ($crop == 'square') {
$min = $w_i;
if ($w_i > $h_i) $min = $h_i;
$w_o = $h_o = $min;
} else {
list($x_o, $y_o, $w_o, $h_o) = $crop;
if ($percent) {
$w_o *= $w_i / 100;
$h_o *= $h_i / 100;
$x_o *= $w_i / 100;
$y_o *= $h_i / 100;
}
if ($w_o < 0) $w_o += $w_i;
$w_o -= $x_o;
if ($h_o < 0) $h_o += $h_i;
$h_o -= $y_o;
}
$img_o = imagecreatetruecolor($w_o, $h_o);
imagecopy($img_o, $img, 0, 0, $x_o, $y_o, $w_o, $h_o);
if ($type == 2) {
return imagejpeg($img_o,$file_output,100);
} else {
$func = 'image'.$ext;
return $func($img_o,$file_output);
}
}
?>
And you can call like this
crop($file_input, $file_output, $crop = 'square',$percent = false);
And also resize function if you need.
<?php
function resize($file_input, $file_output, $w_o, $h_o, $percent = false) {
list($w_i, $h_i, $type) = getimagesize($file_input);
if (!$w_i || !$h_i) {
return;
}
$types = array('','gif','jpeg','png');
$ext = $types[$type];
if ($ext) {
$func = 'imagecreatefrom'.$ext;
$img = $func($file_input);
} else {
return;
}
if ($percent) {
$w_o *= $w_i / 100;
$h_o *= $h_i / 100;
}
if (!$h_o) $h_o = $w_o/($w_i/$h_i);
if (!$w_o) $w_o = $h_o/($h_i/$w_i);
$img_o = imagecreatetruecolor($w_o, $h_o);
imagecopyresampled($img_o, $img, 0, 0, 0, 0, $w_o, $h_o, $w_i, $h_i);
if ($type == 2) {
return imagejpeg($img_o,$file_output,100);
} else {
$func = 'image'.$ext;
return $func($img_o,$file_output);
}
}
?>
resize($file_input, $file_output, $w_o, $h_o, $percent = false);
You can use SimpleImage class found here SimpleImage
[edit] Updated version with many more features here SimleImage Updated
I use this when resizing various images to a smaller thumbnail size while maintaining aspect ratio and exact image size output. I fill the blank area with a colour that suits the background for where the image will be placed, this class supports cropping. Explore the methods cutFromCenter and maxareafill.
For example in your code you would not need to imagecreatefromjpeg() you would simply;
Include the class include('SimpleImage.php');
then;
$im = new SimpleImage();
$im->load($path_to_image_directory . $filename);
$im->maxareafill($output_width,$output_height, 0,0,0); // rgb
$im->save($path_to_image_directory . $filename);
I use this class daily and find it very versatile.
I am using the Blueimp/jQuery-File-Uploader and the Amazon S3 plugin that is available for it and all is working out fine however I need to resize my images to be no more or less that 640px on the shortest side.
my current code is
global $s3;
if (isset($_REQUEST['_method']) && $_REQUEST['_method'] === 'DELETE') {
return "";
}
$upload = isset($_FILES['files']) ? $_FILES['files'] : null;
$info = array();
if ($upload && is_array($upload['tmp_name'])) {
foreach($upload['tmp_name'] as $index => $value) {
$fileTempName = $upload['tmp_name'][$index];
$file_name = (isset($_SERVER['HTTP_X_FILE_NAME']) ? $_SERVER['HTTP_X_FILE_NAME'] : $upload['name'][$index]);
$extension=end(explode(".", $file_name));
$rand = rand(1,100000000);
$sha1 = sha1($rand);
$md5 = md5($sha1);
$filename = substr($md5, 0, 8);
$fileName=$filename.".".$extension;
$fileName = $prefix.str_replace(" ", "_", $fileName);
$response = $s3->create_object($bucket, $fileName, array('fileUpload' => $fileTempName, 'acl' => AmazonS3::ACL_PUBLIC, 'meta' => array('keywords' => 'example, test'),));
if ($response->isOK()) {
$info[] = getFileInfo($bucket, $fileName);
} else {
// echo "<strong>Something went wrong while uploading your file... sorry.</strong>";
}
}
And I have written this bit of PHP however I am not sure as to how I can get the two working together.
$image = new Imagick('test2.jpg');
$imageprops = $image->getImageGeometry();
$w=$imageprops['width'];
$h=$imageprops['height'];
$edge = min($w,$h);
$ratio = $edge / 640;
$tWidth = ceil($w / $ratio);
$tHeight = ceil($h / $ratio);
if ($imageprops['width'] <= 640 && $imageprops['height'] <= 640) {
// don't upscale
} else {
$image->resizeImage($tWidth,$tHeight,imagick::FILTER_LANCZOS, 0.9, true);
}
$image->writeImage("test2-resized.jpg");
any help will be gratefully received, thanks
This is based on the assumption that all code in the OP's message was correct, and simply re-arranged it as requested.
Update: four upvotes (so far) seems to indicate the OP was correct not only regarding the code, but also regarding the magnitude of the issue. I do OSS as a matter of course, so by all means, let me know explicitly if this is of any interest to you so we can improve on this on github (any action is fine -- upvote the question, upvote the answer, post a comment, or any combination thereof).
function resize($imgName, $srcName)
{
$image = new Imagick($imgName);
$imageprops = $image->getImageGeometry();
$w=$imageprops['width'];
$h=$imageprops['height'];
$edge = min($w,$h);
$ratio = $edge / 640;
$tWidth = ceil($w / $ratio);
$tHeight = ceil($h / $ratio);
if ($imageprops['width'] <= 640 && $imageprops['height'] <= 640) {
return $imgName;
} else {
$image->resizeImage($tWidth,$tHeight,imagick::FILTER_LANCZOS, 0.9, true);
}
$extension=end(explode(".", $srcName));
// Change "/tmp" if you're running this on Windows
$tmpName=tempnam("/tmp", "resizer_").".".$extension;
$image->writeImage($tmpName);
return $tmpName
}
global $s3;
if (isset($_REQUEST['_method']) && $_REQUEST['_method'] === 'DELETE') {
return "";
}
$upload = isset($_FILES['files']) ? $_FILES['files'] : null;
$info = array();
if ($upload && is_array($upload['tmp_name'])) {
foreach($upload['tmp_name'] as $index => $value) {
$file_name = (isset($_SERVER['HTTP_X_FILE_NAME']) ? $_SERVER['HTTP_X_FILE_NAME'] : $upload['name'][$index]);
$fileTempName = resize($upload['tmp_name'][$index], $file_name);
$extension=end(explode(".", $file_name));
$rand = rand(1,100000000);
$sha1 = sha1($rand);
$md5 = md5($sha1);
$filename = substr($md5, 0, 8);
$fileName=$filename.".".$extension;
$fileName = $prefix.str_replace(" ", "_", $fileName);
$response = $s3->create_object($bucket, $fileName, array('fileUpload' => $fileTempName, 'acl' => AmazonS3::ACL_PUBLIC, 'meta' => array('keywords' => 'example, test'),));
if ($response->isOK()) {
$info[] = getFileInfo($bucket, $fileName);
} else {
// `echo "<strong>Something went wrong while uploading your file... sorry.</strong>";`
}
unlink($fileTempName);
}