PHP video upload works on windows not in ios safari - php

I'm using PHP to upload mp4 video files and generate thumbnails on Linux environment and I have no Idea why my code works fine on any windows browser but when using my ios safari I
get INVALID FILE.
ini_set('display_errors', 'On'); error_reporting(E_ALL);
require_once '../../vendor/autoload.php' ;
if($_FILES["upload_file"]["name"] != '')
{
$data = explode(".", $_FILES["upload_file"]["name"]);
$extension = $data[1];
$allowed_extension = array("mp4");
if(in_array($extension, $allowed_extension))
{
$name_only = pathinfo($_FILES["upload_file"]['name'], PATHINFO_FILENAME) ; // Main Name Only
$new_video_name = $name_only.'.mp4';
$new_img_name = $name_only.'.jpg';
$path = $_POST["hidden_folder_name"] .'/'. $new_video_name;
$img_path = $_POST["hidden_folder_name"] .'/'.$new_img_name ;
if(move_uploaded_file($_FILES["upload_file"]["tmp_name"], $path))
{
$ffmpeg = FFMpeg\FFMpeg::create(array(
'ffmpeg.binaries' => '/usr/local/bin/ffmpeg',
'ffprobe.binaries' => '/usr/local/bin/ffprobe',
'timeout' => 3600,
'ffmpeg.threads' => 12,
));
$video = $ffmpeg->open($path);
$video->filters()->resize(new FFMpeg\Coordinate\Dimension(320, 180))->synchronize();
$video->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(5))->save($img_path);
echo 'FILE UPLOADED';
}
else
{
echo 'THERE IS AN ERROR';
}
}
else
{
echo 'INVALID FILE';
}
}
else
{
echo 'PLEASE SELECT FILE';
}

This was causing the problem on ios Safari,
if(in_array($extension, $allowed_extension))
{
Removing that and the
else
{
echo 'INVALID FILE';
}
}
Fixed my problem.

Related

[PHP][SLIM] move_uploaded_file never ends with larger files in Hosting24

I have a question.
I'm trying to upload files to a server, this server is hosted by 'Hosting24', i don't know if that matters, anyway, if I try to move files larger than 70mb It never ends to load and never send a response, my server config is okay, it has these values: {"post_max_size":"512M","memory_limit":"1024M"}
I has tryed with $_FILES and ftp transfer and it doesnt works, it never ends of load.
I'm using Slim framework and this is the function:
public function testCode($request, $response, $args)
{
$data = $request->getParsedBody();
$uploadedFiles = $request->getUploadedFiles();
//here take files
$uploadedFile = $uploadedFiles['file_user'];
$nameC = $data['nombre_curso'];
//here set path
$path = "../../scorm/temp/" . $nameC . '/';
//Creating folders
if (!#mkdir($path, 0777, true)) {
$error = error_get_last();
echo $error['message'];
}
$file_name = $uploadedFile->getClientFilename();
$array = explode(".", $file_name);
$ext = $array[1];
//if is a zip file
if ($ext == 'zip') {
$location = $path . "/" . $file_name;
//here move the uploaded file to my selected directory
if (move_uploaded_file($uploadedFile->file, $location)) {
$obj = (object) array("response" => 'works', 'post_max_size' => ini_get('post_max_size'), 'memory_limit' => ini_get('memory_limit'));
$response->withStatus(200);
$response->getBody()->write(json_encode($obj));
return $response;
} else {
$error = error_get_last();
echo $error['message'] . " it couldn't be moved";
}
} else {
echo "no zip";
}
}

file not found exception in laravel

I am facing some problem while uploading image in laravel framework of my project .I checked image is uploading to folder , but still this error is coming
Below is coding
/////////// Course Image ///////////
$tmp_name1 = $course_image['tmp_name'];
$type1 = $course_image['type'];
$name1 = $course_image['name'];
$res1 = $this->upload_file($tmp_name1, $name1);
if ($res1) {
$course_image_url = $res1;
} else {
$course_image_url = "";
}
function upload_file($source, $name) {
$list = explode(".", $name);
$ext = $list[count($list) - 1];
$ext = strtolower($ext);
if (in_array($ext, $this->file_extension)) {
$filename = md5(date("YmdHis") . microtime() . rand(100, 100000000)) . "." . $ext;
$destination = "public/uploads/" . $filename;
$res = move_uploaded_file($source, $destination);
if ($res) {
return $destination = "uploads/" . $filename;
} else {
$message = "Internal server error";
(json_encode(array("responseCode" => "500", "responseMsg" => array("status" => "error", "statusReason" => $message))));
}
} else {
$message = "Invalid file extention";
(json_encode(array("responseCode" => "500", "responseMsg" => array("status" => "error", "statusReason" => $message))));
}
}
There are lots of codes , I posted only the required one .
You should follow the Laravel Example for Uploading Files.
I.e., you can check if a file has been uploaded successfully using:
if ($request->hasFile('image')) {
//
}
And you can move / rename a file using:
$request->file('image')->move($destinationPath);
or
$request->file('image')->move($destinationPath, $fileName);
I found that issue .
Go to line number 66 of this path(D:\xampp\htdocs\blog\vendor\laravel\framework\src\Illuminate\Http\UploadedFile.php) in your project folder .or search the text instanceof static.
After it remove the "instanceof static" ,then it is working fine.
Thanx

image upload error in php codeigniter [The upload path does not appear to be valid.]

I was using php codeigniter 2.x now i updated it to 3.x, after that my upload code is not working.
this is my code. please go though it.
when this code is working always getting the error
The upload path does not appear to be valid.
$this->load->library('upload');
$session = $this->ifisSession();
$uploadfolder = 'profileImgs';
$fullPath = 'abc';
$imageconfig['upload_path'] = $fullPath;
$imageconfig['max_size'] = (1024); // 1mb file size
$imageconfig['allowed_types'] = 'gif|jpg|png';
$imageconfig['max_width'] = (1024 );
$imageconfig['max_height'] = (1024);
$fieldName = 'profileimage';
//$uploadfilename = $_FILES[$fieldName];
$uploadfilename = $_FILES[$fieldName]['name'];
// printv($uploadfilename, 'this ihere');
$fileinfo = pathinfo($uploadfilename);
if (isset($fileinfo['extension'])) {
$ext = $fileinfo['extension'];
$imageconfig['file_name'] = $session['firstname'] . '_' . $session['user_id_pk'] . '_' . uniqid() . '.' . $ext;
}
$this->load->library('upload', $imageconfig);
if (!$this->upload->do_upload('profileimage')) {
$error = $this->upload->display_errors();
$data['data']['profileUpdate_error'] = $error;
// move to profile page with erro message
} else {
$profileUploadinfo = array('upload_data' => $this->upload->data());
$profileimgurl = '';
$res = $this->Model_userinfo->updateProfileImg($session['user_id_pk'], $profileimgurl);
if($res > 0){
$data['data']['profileUpdate_success'] = 'Profile Updated';
}else{
$data['data']['profileUpdate_error'] = 'Profile Not updated';
}
}

move uploaded file success but could not find file in folder

I have the following code
public function upload() {
if($_FILES){
$this->load->model('account/customer');
$file = $_FILES['profile'];
$file_name = $file['name'];
// $ext = end(explode('.', $file_name));
// $file_name = 'na_'.md5(time()).'.'.$ext;
echo $file_content = $file['tmp_name'];
$data = array('customer_id' => $this->customer->getId(), 'img_url' => $file['name']);
$this->model_account_customer->profileImage($data);
echo 'test/'.$file_name;
$img = move_uploaded_file($file['tmp_name'], 'test/'.$file['name']);
if($img) {
$return = json_encode(array('status' => 1));
} else {
$return = json_encode(array('status' => 0));
}
echo $return;
}
}
The above code returning status as 1 but could not see the file in folder.
I check folder permission is 0777
Try appending a / in front of the path
move_uploaded_file($file['tmp_name'], '/test/'.$file['name']);

How can I upload a file to amazon S3 with Codeigniter/PHP?

I'm trying to upload a file to my Amazon S3 bucket. My friend had this working on our site in the past but a year later its busted and I can't figure out what's wrong. We are using the S3 PHP library developed by Geoff gaudreault.
This library looks pretty straightforward to me, really it looks like there is one key function: putObject().
Unfortunately, I'm not even getting out of the gate. I'm getting the following error message:
Error 324 (net::ERR_EMPTY_RESPONSE): The server closed the connection without sending any data.
Here's my codeigniter PHP for my upload form action:
function s3(){
$config['upload_path'] = $_SERVER["DOCUMENT_ROOT"].'/temp/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '1000000';
$config['max_width'] = '1024000';
$config['max_height'] = '768000';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
print_r($error);
echo 'failure';
}
else
{
$data = array('upload_data' => $this->upload->data());
$fn = $data['file_name'];
$type = substr($fn, strrpos($fn, '.') + 1);
$this->load->library('s3');
$temp_file_path = $_SERVER["DOCUMENT_ROOT"]."/temp/" . $data['file_name'];
$contents = read_file($temp_file_path); // will this blow up or timeout for large files?!
$newFileName = uniqid().".".substr($temp_file_path, strrpos($temp_file_path, '.') + 1);
$contentPath = "mysite.com/Images";
$this->s3->putObject($newFileName, $contents, $contentPath, 'private', $type);
echo 'success';
}
}
Does anyone have any thoughts?
I switched to a different S3 PHP library, which is also referred to as S3.php, that is part of this really nice Netuts tutorial source code.
Just plugging in my AWS keys and bucket name into the demo's page.php file, I was able to upload to my bucket in like 2 minutes. So this tutorial is super easy. Very exciting!
in codeigniter
Here link to upload and delete image in s3 bucket
<?php
function profile_upload()
{
//print_r($_FILES);
if ($this->session->userdata('user_login')) {
$file = $_FILES['agent_profile_file']['tmp_name'];
if (file_exists($file)) {
$allowedExts = array("gif", "jpeg", "jpg", "png");
$typefile = explode(".", $_FILES["agent_profile_file"]["name"]);
$extension = end($typefile);
if (!in_array(strtolower($extension), $allowedExts)) {
//not image
$data['message'] = "images";
} else {
$userid = $this->session->userdata['user_login']['userid'];
$full_path = "agent_image/" . $userid . "/profileImg/";
/*if(!is_dir($full_path)){
mkdir($full_path, 0777, true);
}*/
$path = $_FILES['agent_profile_file']['tmp_name'];
$image_name = $full_path . preg_replace("/[^a-z0-9\._]+/", "-", strtolower(uniqid() . $_FILES['agent_profile_file']['name']));
//move_uploaded_file($path,$image_name);
$data['message'] = "sucess";
$s3_bucket = s3_bucket_upload($path, $image_name);
if ($s3_bucket['message'] == "sucess") {
$data['imagename'] = $s3_bucket['imagepath'];
$data['imagepath'] = $s3_bucket['imagename'];
}
//print_r($imagesizedata);
//image
//use $imagesizedata to get extra info
}
} else {
//not file
$data['message'] = "images";
}
} else {
$data['message'] = "login";
}
echo json_encode($data);
//$file_name2 = preg_replace("/ /", "-", $file_name);
}
// Helper file add code
// image compress code
function compress($source, $destination, $quality)
{
ob_start();
$info = getimagesize($source);
if ($info['mime'] == 'image/jpeg') {
$image = imagecreatefromjpeg($source);
} elseif ($info['mime'] == 'image/gif') {
$image = imagecreatefromgif($source);
} elseif ($info['mime'] == 'image/png') {
$image = imagecreatefrompng($source);
}
$filename = tempnam(sys_get_temp_dir(), "beyondbroker");
imagejpeg($image, $filename, $quality);
//ob_get_contents();
$imagedata = ob_end_clean();
return $filename;
}
// type for if image then it will reduce size
// site for it in web of mobile because mobile webservice image will in base 64
// $tempth will file temp path
// $image_path will file where to save path
function s3_bucket_upload($temppath, $image_path, $type = "image", $site = "web")
{
$bucket = "bucket-name";
$data = array();
$data['message'] = "false";
// For website only
if ($site == "web") {
if ($type == "image") {
$file_Path = compress($temppath, $image_path, 90);
} else {
$file_Path = $temppath;
}
}
try {
$s3Client = new S3Client([
'version' => 'latest',
'region' => 'us-west-2',
'credentials' => [
'key' => 'aws-key',
'secret' => 'aws-secretkey',
],
]);
// For website only
if ($site == "web") {
$result = $s3Client->putObject([
'Bucket' => $bucket,
'Key' => $image_path,
'SourceFile' => $file_Path,
//'body'=> $file_Path,
'ACL' => 'public-read',
//'StorageClass' => 'REDUCED_REDUNDANCY',
]);
$data['message'] = "sucess";
$data['imagename'] = $image_path;
$data['imagepath'] = $result['ObjectURL'];
} else {
// $tmp = base64_decode($base64);
$upload = $s3Client->upload($bucket, $image_path, $temppath, 'public-read');
$data['message'] = "sucess";
$data['imagepath'] = $upload->get('ObjectURL');
}
} catch (Exception $e) {
$data['message'] = "false";
// echo $e->getMessage() . "\n";
}
return $data;
}

Categories