Image upload not working in IE? - php

PLEASE HELP!
I've an image uploader which seems to be working great in every browser except IE :(
It seems to just get stuck with a loading GIF and do nothing. Is it likely to be the above code or could it be the JavaScript in the actual upload page?
Any suggestions?...
<?php
session_start();
include 'resizeimage.php';
include '../conf/config.php';
$loggedin = $_SESSION['loggedin_user'];
$getmid = mysql_query("SELECT * FROM members WHERE Username = '$loggedin'");
while($iamid = mysql_fetch_array($getmid))
{
$member_id = $iamid['ID'];
}
$path = "../m/members_image/".$member_id."/temp/";
$valid_formats = array("jpg", "jepg", "png", "gif", "pjpeg", "pjpg", "PJPEG", "PJPG", "JPG", "JPEG", "PNG", "GIF");
$pid = date("Ymdhis");
$pid = str_replace(".", "", "$pid");
$pid = $member_id;
/*$_SESSION['pid'] = $pid;*/
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST") {
$name = $_FILES['photoimg']['name'];
$size = $_FILES['photoimg']['size'];
if(strlen($name)) {
$extarr = explode(".", $name);
$ext = end($extarr);
if(in_array($ext,$valid_formats)) {
if($size<(3000000)) {
$actual_image_name = $pid.".".$ext;
$tmp = $_FILES['photoimg']['tmp_name'];
if(move_uploaded_file($tmp, "$path$actual_image_name")) {
$imgsrc = "$path$actual_image_name";
list($width, $height) = getimagesize($imgsrc);
$image = new SimpleImage();
$image->load($imgsrc);
if ( $width > $height ) { $image->resizeToWidth(960); }
else { $image->resizeToHeight(600); }
$image->save("$imgsrc");
list ($width1, $height1) = getimagesize($imgsrc);
if ( $width1 > 960 ) {
$image->resizetoWidth(960);
$image->save("$imgsrc");
} else {}
if ( $height1 > 600 ) {
$image->resizetoHeight(600);
$image->save("$imgsrc");
} else {}
echo "<img class='preview'>";
} else { echo "failed"; };
} else { echo "Image file size max 3 MB"; }
} else { echo "Invalid file format.."; }
} else { echo "Please select image..!"; }
exit;
}
?>
JavaScript:
<script type="text/javascript" >
$(document).ready(function() {
$('#photoimg').live('change', function() {
$("#btn_contaier_browse").hide();
$("#preview").html('');
$("#preview").html("<div class='splittermessages'></div><br><table border='0'><tr><td><img width=60 src='/images/loading.gif'></td><td>Uploading image ..</td></tr></table>");
$("#imageform").ajaxForm({
target: '#preview',
success: showCrop
}).submit();
});
});
function showCrop() {
$("#btn_contaier_browse").show();
$("#tiltusm").html('Make thumbnails.. crop your image');
$('#currentElement').attr("src", $('#currentElement').attr("src"));
$("#currentElement").css("display","block");
$('#currentElement').hide();
$('#currentElement').fadeIn(500);
}
function reloadz() {
setTimeout(function(){ window.location = '/photos.html';}, 3000);
}
</script>

i use jquery with html form
include all the jquery files
then use the following code
html
<head>
$(function() {
$('#submitBtn').bind('click', function(e) {
$('#myForm').submit();
$('#myFrame').live('change', function(e) {
//read iframe and put your own success message
});
});
});
</head>
<body>
<form id="myForm" action="myAction.php" enctype="multipart/formdata" target="myFrame">
<input id="file" type="file" />
<input type="submit" id="submitBtn" />
</form>
<iframe id="myFrame" name="myFrame" ></iframe>
</body>

Related

php creating thumbnail on multiple file upload and saving both thumbnail and image in two different directories

I am trying to upload multiple images to a folder in my website. While the file upload works without a problem, I am trying to integrate creating thumbnail for all the images uploaded in the same function which is not working.
HTML Form:
<form class="navbar-form pull-left" action="fileupload.php" name="fileupload" method="post" enctype="multipart/form-data">
<label for="file" style="cursor: pointer;padding:5px 0 0 0;font-weight:normal" title="Add Images">IMAGES</label>
<input type="file" name="file[]" multiple id="file"><br>
</form>
Javascript:
function _id(e) {return document.getElementById(e)}
_id('file').onchange = function() {
var theFile = this.files;
if(theFile.length === 1) {
var uploader = new XMLHttpRequest();
var file = new FormData();
file.append("file", theFile[0]);
uploader.onreadystatechange = function() {
if(uploader.readyState === 4 && uploader.status === 200) {
show_message('Uploading Image');
console.log(uploader.responseText);
}
}
uploader.open('POST','fileupload.php',true);
uploader.send(file);
} else {
var start = 0,
setter,
buff = true;
setter = setInterval(function() {
if (buff === true) {
show_message('Uploading Images');
buff = false;
var uploader = new XMLHttpRequest();
var file = new FormData();
file.append('file', theFile[start]);
uploader.onreadystatechange = function() {
if(uploader.readyState === 4 && uploader.status === 200) {
console.log(uploader.responseText);
start++;
buff = true;
}
}
uploader.open('POST','fileupload.php',true);
uploader.send(file);
}
if(start >= theFile.length) {
clearInterval(setter);
}
}, 200)
}
}
fileupload.php
<?php
session_start();
$database = $_SESSION['folder'];
$match = $_SESSION['matchLst'];
$tardir = "/var/www/html/projects/" . $database . "/" . $match . "/";
$thumb = $match . "_thumb/";
$thumbdir = $tardir . $thumb;
function createThumbnail($filename) {
if($filename) {
$im = imagecreatefromjpeg($tardir . $filename);
}
$x = imagesx($im);
$y = imagesy($im);
$nx = 100;
$ny = 100;
$nm = imagecreatetruecolor($nx, $ny);
imagecopyresized($nm, $im, 0, 0, 0, 0, $nx, $ny, $x, $y);
if(!file_exists($thumbdir)) {
if(mkdir($thumbdir)) {
imagejpeg($nm, $thumbdir . $filename);
} else {
die("Thumbnail directory could not be created");
}
} else {
imagejpeg($nm, $thumbdir . $filename);
}
}
if(!isset($_FILES['file'])){die();}
if(isset($_FILES['file'])) {
if($_FILES['file']['name']) {
$filename = $_FILES['file']['name'];
$source = $_FILES['file']['tmp_name'];
$target = $tardir . $filename;
move_uploaded_file($source, $target);
createThumbnail($filename);
echo "Images uploaded";
}
}
?>
I am facing 2-3 problems:
In the fileupload.php file if I comment out the createThumbnail($filename) then I am able to upload multiple files without a problem. When I include createThumbnail function, neither file upload nor thumbnail creation happens. I have tried various examples given here and git - however, not able to create thumbnail nor save it on to a folder.
$tardir is not set here :
function createThumbnail($filename) {
if($filename) {
$im = imagecreatefromjpeg($tardir . $filename);
}
You should replace your function call :
createThumbnail($filename);
By :
createThumbnail($tardir . $filename);
And don't use $tardir in your function.
Be careful when you set an absolute path :
$tardir = "/var/www/html/projects/" . $database . "/" . $match . "/";
Your script will be broken if the path changes. Instead you can use magic-constants like DIR and/or realpath()

How to insert multiple images and move into folder in php?

$(document).ready(function(){
$("#add_small").click(function(event){
event.preventDefault();
$(".add_small").append('<div class="form-group">\
<label for="product_small_image">Product Image:</label>\
<input type="file" name="product_image[]" class="product_image" value=""/>\
Remove\
<div>');
});
jQuery(document).on('click', '.remove_small', function() {
jQuery(this).parent().remove();
return false;
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form method="post" name="user_registration" class="register" enctype="multipart/form-data">
<div class="form-group">
<label for="product_small_image">Product Image:</label>
<input type="file" name="product_image[]" class="product_image" value=""/>
Add
</div>
<div class="add_small"></div>
<br/>
<input name="submit" type="submit" class="submit" value="Submit" />
</form>
<?php
if(isset($_POST['submit']))
{
$file_ary = reArrayFiles($_FILES['product_images']);
foreach ($file_ary as $file)
{
//print 'File Name: ' . $file['name'];
//print 'File Type: ' . $file['type'];
//print 'File Size: ' . $file['size'];
$folder_Path = "../images/product_image/";
$banner_image_name = str_replace(" ", "", strtolower(basename($file['name'])));
$banner_image_name_upload = $folder_Path.$banner_image_name;
//$banner_image_tmp = $_FILES['product_image']['tmp_name'];
$imageFileType = strtolower(pathinfo($banner_image_name,PATHINFO_EXTENSION));
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" )
{
$msg = "<div class='alert alert-success'>Sorry, only JPG, JPEG, PNG & GIF files are allowed.</div>";
}
else
{
if (move_uploaded_file($banner_image_name_upload))
{
$set_width = 600;
$set_height = 600;
$banner_image_source_file = $banner_image_name_upload;
$banner_image_save_file = $banner_image_name_upload;
list($width_orig, $height_orig) = getimagesize($banner_image_source_file);
$image_p = imagecreatetruecolor($set_width, $set_height);
$image = imagecreatefromjpeg($banner_image_source_file);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $set_width, $set_height, $width_orig, $height_orig);
imagejpeg($image_p, $banner_image_save_file, 75);
$query = "insert into inventory_add_in_stock(`product_image`)values('".$file['name']."')";
echo $query;
$result = mysqli_query($con,$query);
if($result==true)
{
$msg = "<div class='alert alert-success'>Record Save Successfully</div>";
}
else
{
$msg = "<div class='alert alert-danger'>Unable to Save Please Try Again !!!</div>";
}
}
else
{
$msg = "<div class='alert alert-danger'>Unable to Proceeed Please Try Again !!!</div>";
}
}
}
}
function reArrayFiles(&$file_post) {
$file_ary = array();
$file_count = count($file_post['name']);
$file_keys = array_keys($file_post);
for ($i=0; $i<$file_count; $i++) {
foreach ($file_keys as $key) {
$file_ary[$i][$key] = $file_post[$key][$i];
}
}
return $file_ary;
}
?>
This is my duplicate question. I have create add and remove more file using jQuery. Now, What happen when I click on add button it show me to choose another file similarly again and again. I am able to upload multiple file like this. But the problem is that when I click on submit button to insert into the database and move image to the folder it show me error i.e.
I found the reason in your code:
$banner_image_tmp = $_FILES['product_image']['tmp_name'];
The $banner_image_tmp will return an array. So, there will be an error
move_uploaded_file() expects parameter 1 to be string, array given
http://php.net/manual/en/features.file-upload.multiple.php. Your code should be:
if(isset($_POST['submit']))
{
$file_ary = reArrayFiles($_FILES['product_image']);
foreach ($file_ary as $file) {
print 'File Name: ' . $file['name'];
print 'File Type: ' . $file['type'];
print 'File Size: ' . $file['size'];
//Your custom code here
}
}
function reArrayFiles(&$file_post) {
$file_ary = array();
$file_count = count($file_post['name']);
$file_keys = array_keys($file_post);
for ($i=0; $i<$file_count; $i++) {
foreach ($file_keys as $key) {
$file_ary[$i][$key] = $file_post[$key][$i];
}
}
return $file_ary;
}

PHP $_FILES same image name

I am trying to upload multiple images to php server, But for some reason it is using first image name for all the uploaded images, saving to same image name. I want it to save to their filename in the source folder. Like Banner1.jpg,Banner2.jpg and Banner3.jpg should be saved. But it is saving first image thrice.
$filesCount = count($_FILES['photos']['name']);
$success = 0;
for($i = 0; $i < $filesCount; $i++)
{
$uploadedfile = $_FILES['photos']['tmp_name'][$i];
if($uploadedfile)
{
$filename = stripcslashes($_FILES['photos']['name'][$i]);
$extension = $this->getExtension($filename);
$extension = strtolower($extension);
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
{
$change='<div class="msgdiv">Unknown Image extension </div>';
}
else
{
$size = filesize($_FILES['photos']['tmp_name'][$i]);
}
if($size > MAX_SIZE*1024)
{
$change='<div class="msgdiv">You have exceeded the size limit!</div> ';
}
if($extension=="jpg" || $extension=="jpeg" )
{
$uploadedfile = $_FILES['photos']['tmp_name'][$i];
$src = imagecreatefromjpeg($uploadedfile);
}
else if($extension=="png")
{
$uploadedfile = $_FILES['photos']['tmp_name'][$i];
$src = imagecreatefrompng($uploadedfile);
}
else
{
$src = imagecreatefromgif($uploadedfile);
}
list($width,$height)=getimagesize($uploadedfile);
$newwidth=1024;
$newheight=($height/$width)*$newwidth;
$tmp=imagecreatetruecolor($newwidth,$newheight);
$newwidth1=300;
$newheight1=($height/$width)*$newwidth1;
$tmp1=imagecreatetruecolor($newwidth1,$newheight1);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
imagecopyresampled($tmp1,$src,0,0,0,0,$newwidth1,$newheight1,$width,$height);
$filenameee = "server/php/rental/". $_FILES['photos']['name'][$i];
$filenameee1 = "server/php/rental/small/". $_FILES['photos']['name'][$i];
imagejpeg($tmp,$filenameee,100);
imagejpeg($tmp1,$filenameee1,100);
imagedestroy($src);
imagedestroy($tmp);
imagedestroy($tmp1);
if(mysql_query("INSERT INTO fc_rental_photos(product_image,product_id) VALUES('$filename','$prd_id')"))
{
$success++;
}
}
Here is the input field i am using to upload images.
<form id="imageform" method="post" enctype="multipart/form-data" action="/path-to-controller-method/">
<input type="file" name="photos[]" id="photoimg" multiple onchange="imageval();">
</form>
IMageVal
function imageval(){ /*Image size validation*/
var fi = document.getElementById('photoimg');
if (fi.files.length > 0) { // FIRST CHECK IF ANY FILE IS SELECTED.
for (var i = 0; i <= fi.files.length - 1; i++) {
var fileName, fileExtension, fileSize, fileType, dateModified;
fileName = fi.files.item(i).name;
fileExtension = fileName.replace(/^.*\./, '');
if (fileExtension == 'png' || fileExtension == 'jpg' || fileExtension == 'jpeg') {
var reader = new FileReader();
//Read the contents of Image File.
reader.readAsDataURL(fi.files.item(i));
reader.onload = function (e) {
//Initiate the JavaScript Image object.
var image = new Image();
//Set the Base64 string return from FileReader as source.
image.src = e.target.result;
//Validate the File Height and Width.
image.onload = function () {
var height = this.height;
var width = this.width;
if (width < 1450 || height < 500) {
alert("Image Height and Width should be Above 1450 * 500 px.");
return false;
}
<?php if($aws == 'Yes') echo "uploadImage_aws();";else echo "uploadImage();";?>
};
}
}
else
{
alert("Photo only allows file types of PNG, JPG, JPEG. ");
}
}
}
}
UploadImage
function uploadImage()
{
$("#imageform").ajaxForm({target: '#preview',
beforeSubmit:function(){
$("#imageloadstatus").show();
$("#imageloadbutton").hide();
},
success:function(){
$("#imageloadstatus").hide();
$("#imageloadbutton").show();
},
error:function(){
$("#imageloadstatus").hide();
$("#imageloadbutton").show();
}
}).submit();
}
You have to check if the data already exists, and if not to rename it.
if(file_exists($new_path)) {
$id = 1;
do {
$new_path = $upload_folder.$filename.'_'.$id.'.'.$extension;
$id++;
} while(file_exists($new_path));
}
For example
$new_path = $upload_folder.$filename.'.'.$extension;

imagecopyresampled() my image turns black after resizing it- CakePhp3

This when I send ajax request to my controller to crop and resize it, instead it resize it but my image turns black. I even tried adding header so that my browser can understands that it is a valid image file format. Where I am missing?
**My ajax call to controller**
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('#change-pic').on('click', function(e){
jQuery('#changePic').show();
jQuery('#change-pic').hide();
});
jQuery('#photoimg').on('change', function()
{
jQuery("#preview-avatar-profile").html('');
jQuery("#preview-avatar-profile").html('Uploading....');
jQuery("#cropimage").ajaxForm(
{
target: '#preview-avatar-profile',
success: function() {
jQuery('img#photo').imgAreaSelect({
aspectRatio: '1:1',
onSelectEnd: getSizes,
});
jQuery('#image_name').val(jQuery('#photo').attr('file-name'));
}
}).submit();
});
jQuery('#btn-crop').on('click', function(e){
e.preventDefault();
params = {
//targetUrl: 'profile.php?action=save',
targetUrl: 'http://172.16.0.60/cakephp/users/croppedimage',
//action: 'save',
x_axis: jQuery('#hdn-x1-axis').val(),
y_axis : jQuery('#hdn-y1-axis').val(),
x2_axis: jQuery('#hdn-x2-axis').val(),
y2_axis : jQuery('#hdn-y2-axis').val(),
thumb_width : jQuery('#hdn-thumb-width').val(),
thumb_height:jQuery('#hdn-thumb-height').val()
};
saveCropImage(params);
});
function getSizes(img, obj)
{
var x_axis = obj.x1;
var x2_axis = obj.x2;
var y_axis = obj.y1;
var y2_axis = obj.y2;
var thumb_width = obj.width;
var thumb_height = obj.height;
if(thumb_width > 0)
{
jQuery('#hdn-x1-axis').val(x_axis);
jQuery('#hdn-y1-axis').val(y_axis);
jQuery('#hdn-x2-axis').val(x2_axis);
jQuery('#hdn-y2-axis').val(y2_axis);
jQuery('#hdn-thumb-width').val(thumb_width);
jQuery('#hdn-thumb-height').val(thumb_height);
}
else
alert("Please select portion..!");
}
function saveCropImage(params) {
jQuery.ajax({
url: params['targetUrl'],
cache: false,
dataType: "html",
data: {
action: params['action'],
id: jQuery('#hdn-profile-id').val(),
t: 'ajax',
w1:params['thumb_width'],
x1:params['x_axis'],
h1:params['thumb_height'],
y1:params['y_axis'],
x2:params['x2_axis'],
y2:params['y2_axis'],
image_name :jQuery('#image_name').val()
},
type: 'Post',
// async:false,
success: function (response) {
jQuery('#changePic').hide();
jQuery('#change-pic').show();
jQuery(".imgareaselect-border1,.imgareaselect-border2,.imgareaselect-border3,.imgareaselect-border4,.imgareaselect-border2,.imgareaselect-outer").css('display', 'none');
jQuery("#avatar-edit-img").attr('src', response);
jQuery("#preview-avatar-profile").html('');
jQuery("#photoimg").val('');
},
error: function (xhr, ajaxOptions, thrownError) {
alert('status Code:' + xhr.status + 'Error Message :' + thrownError);
}
});
}
});
</script>
This is one first when I upload the image and preview it.
public function wall()
{
$post = isset($_POST) ? $_POST: array();
$max_width = "500";
$userId = isset($post['hdn-profile-id']) ? intval($post['hdn-profile-id']) : 0;
// $path = 'http://172.16.0.60/cakephp/webroot/img/tmp';
$path = WWW_ROOT.'img/tmp/' ;
$valid_formats = array("jpg", "png", "gif", "bmp","jpeg");
$name = $_FILES['photoimg']['name'];
$size = $_FILES['photoimg']['size'];
if(strlen($name))
{
list($txt, $ext) = explode(".", $name);
if(in_array($ext,$valid_formats))
{
if($size<(1024*1024)) // Image size max 1 MB
{
$actual_image_name = 'avatar' .'_'.$userId .'.'.$ext;
$filePath = $path .'/'.$actual_image_name;
$tmp = $_FILES['photoimg']['tmp_name'];
if(move_uploaded_file($tmp, $filePath))
{
// /$this->setPassword($this->request->data['password']);
$width = $this->getWidth($filePath);
$height = $this->getHeight($filePath);
//Scale the image if it is greater than the width set above
if ($width > $max_width)
{
$scale = $max_width/$width;
$uploaded = $this->resizeImage($filePath,$width,$height,$scale);
}
else
{
$scale = 1;
$uploaded = $this->resizeImage($filePath,$width,$height,$scale);
}
/*
echo "<img id='photo' file-name='".$actual_image_name."' class='' src='".'file://'.$filePath.'?'.time()."' class='preview'/>";
*/
$mypath = '/cakephp/img/tmp/'.$actual_image_name;
echo "<img id='photo' file-name='".$actual_image_name."' class='' src='".$mypath."' class='preview'/>";
}
else
echo "failed";
}
else
echo "Image file size max 1 MB";
}
else
echo "Invalid file format..";
}
else
echo "Please select image..!";
exit;
}
My Controller code where I use the function imagecopyresampled() but idk where I am going wrong.?
Any solution
public function croppedimage()
{
header('Content-Type: image/png');
$post = isset($_POST) ? $_POST: array();
$userId = isset($post['id']) ? intval($post['id']) : 0;
//$path ='\images\uploads\tmp';
$path = WWW_ROOT.'img/tmp/uploads/' ;
$t_width = 300; // Maximum thumbnail width
$t_height = 300; // Maximum thumbnail height
if(isset($_POST['t']) and $_POST['t'] == "ajax")
{
extract($_POST);
//$img = get_user_meta($userId, 'user_avatar', true);
//$filePath = $path .'/'.$actual_image_name;
$imagePath = $path.$_POST['image_name'];
$ratio = ($t_width/$w1);
$nw = ceil($w1 * $ratio);
$nh = ceil($h1 * $ratio);
$nimg = imagecreatetruecolor($nw,$nh);
$im_src = imagecreatefromjpeg($imagePath);
imagecopyresampled($nimg,$im_src,0,0,$x1,$y1,$nw,$nh,$w1,$h1);
imagejpeg($nimg,$imagePath,90);
}
echo $imagePath.'?'.time();;
exit(0);
die();
}

PHP video upload and checking video type

I created my upload file with video size and type validation. Only webm, mp4 and ogv file types are allowed and 2gb file size max. My php code:
if (isset($_POST['submit']))
{
$file_name = $_FILES['file']['name'];
$file_type = $_FILES['file']['type'];
$file_size = $_FILES['file']['size'];
$allowed_extensions = array("webm", "mp4", "ogv");
$file_name_temp = explode(".", $file_name);
$extension = end($file_name_temp);
$file_size_max = 2147483648;
if (!empty($file_name))
{
if (($file_type == "video/webm") || ($file_type == "video/mp4") || ($file_type == "video/ogv") &&
($file_size < $file_size_max) && in_array($extension, $allowed_extensions))
{
if ($_FILES['file']['error'] > 0)
{
echo "Unexpected error occured, please try again later.";
} else {
if (file_exists("secure/".$file_name))
{
echo $file_name." already exists.";
} else {
move_uploaded_file($_FILES["file"]["tmp_name"], "secure/".$file_name);
echo "Stored in: " . "secure/".$file_name;
}
}
} else {
echo "Invalid video format.";
}
} else {
echo "Please select a video to upload.";
}
}
My html code:
<form action="upload_file.php" method="post" enctype="multipart/form-data">
<input type="file" name="file"><br />
<input type="submit" name="submit" value="Submit">
</form>
I'am always getting "Invalid video format.". I downloaded webm, mp4 and ogv video files from flowplayer website to test my little upload script.
http://stream.flowplayer.org/bauhaus/624x260.webm
http://stream.flowplayer.org/bauhaus/624x260.mp4
http://stream.flowplayer.org/bauhaus/624x260.ogv
Your extensions were not correctly being validated.. try this
if (isset($_POST['submit']))
{
$file_name = $_FILES['file']['name'];
$file_type = $_FILES['file']['type'];
$file_size = $_FILES['file']['size'];
$allowed_extensions = array("webm", "mp4", "ogv");
$file_size_max = 2147483648;
$pattern = implode ($allowed_extensions, "|");
if (!empty($file_name))
{ //here is what I changed - as you can see above, I used implode for the array
// and I am using it in the preg_match. You pro can do the same with file_type,
// but I will leave that up to you
if (preg_match("/({$pattern})$/i", $file_name) && $file_size < $file_size_max)
{
if (($file_type == "video/webm") || ($file_type == "video/mp4") || ($file_type == "video/ogv"))
{
if ($_FILES['file']['error'] > 0)
{
echo "Unexpected error occured, please try again later.";
} else {
if (file_exists("secure/".$file_name))
{
echo $file_name." already exists.";
} else {
move_uploaded_file($_FILES["file"]["tmp_name"], "secure/".$file_name);
echo "Stored in: " . "secure/".$file_name;
}
}
} else {
echo "Invalid video format.";
}
}else{
echo "where is my mojo?? grrr";
}
} else {
echo "Please select a video to upload.";
}
}
function fileSelected() {
var inputs = document.getElementsByClassName('myclass');
var input = inputs[0];
var file = input.files[0];
var name = file.name;
var size = file.size;
var type = file.type;
//alert("type: "+type);
if(type!="video/mp4")
{
alert("NOT SUITABLE EXTENSION SELECTED");
}
filesArray.push({ name: name, size: size });
}
<input type="file" accept="video/*" class=" form-control btn btn-primary myclass" required name="file1" id="file1" onchange="fileSelected();">

Categories