PHP: exif_imagetype() not working? - php

I have this extension checker:
$upload_name = "file";
$max_file_size_in_bytes = 8388608;
$extension_whitelist = array("jpg", "gif", "png", "jpeg");
/* checking extensions */
$path_info = pathinfo($_FILES[$upload_name]['name']);
$file_extension = $path_info["extension"];
$is_valid_extension = false;
foreach ($extension_whitelist as $extension) {
if (strcasecmp($file_extension, $extension) == 0) {
$is_valid_extension = true;
break;
}
}
if (!$is_valid_extension) {
echo "{";
echo "error: 'ext not allowed!'\n";
echo "}";
exit(0);
}
And then i added this:
if (exif_imagetype($_FILES[$upload_name]['name']) != IMAGETYPE_GIF
OR exif_imagetype($_FILES[$upload_name]['name']) != IMAGETYPE_JPEG
OR exif_imagetype($_FILES[$upload_name]['name']) != IMAGETYPE_PNG) {
echo "{";
echo "error: 'This is no photo..'\n";
echo "}";
exit(0);
}
As soon when I added this to my imageupload function, the function stops working. I dont get any errors, not even the one i made myself "this is no photo", what could be wrong?
Just checked with my host. They support the function exif_imagetype()

Here is the example with the switch usage:
switch(exif_imagetype($_FILES[$upload_name]['name'])) {
case IMAGETYPE_GIF:
case IMAGETYPE_JPEG:
case IMAGETYPE_PNG:
break;
default:
echo "{";
echo "error: 'This is no photo..'\n";
echo "}";
exit(0);
}
Your script can be used too, but you have to put AND between conditions:
if (exif_imagetype($_FILES[$upload_name]['name']) != IMAGETYPE_GIF
AND exif_imagetype($_FILES[$upload_name]['name']) != IMAGETYPE_JPEG
AND exif_imagetype($_FILES[$upload_name]['name']) != IMAGETYPE_PNG) {
echo "{";
echo "error: 'This is no photo..'\n";
echo "}";
exit(0);
}

There's a better, shorter way to get image types, which I'm currently using (can't be sure if it will works as it is not documented in PHP.net as image_type_to_mime_type() can also take an integer as input):
function get_image_type( $image_path_or_resource ) {
$img = getimagesize( $image_path_or_resource );
if ( !empty( $img[2] ) ) // returns an integer code
return image_type_to_mime_type( $img[2] );
return false;
}
echo get_image_type( 'somefile.gif' );
// image/gif
echo get_image_type( 'path/someotherfile.jpg' );
// image/jpeg
$image = get_image_type( 'somefile.gif' );
if ( !empty( $image ) ){
// fine, let's do some more coding
} else {
// bad image :(
}

if (exif_imagetype($_FILES['image']['tmp_name']) != IMAGETYPE_JPEG
AND exif_imagetype($_FILES['image']['tmp_name']) != IMAGETYPE_PNG)
{
enter code here
}
You can use like that. Hope this is will be helpful

Related

exif data, php uploaded image rotation

I'm having a hard time implemeting the php code will ensure that all uploaded photos will be oriented correctly upon upload.
here is my upload.php function ...
function process_image_upload($field)
{
if(!isset($_FILES[$field]['tmp_name']) || ! $_FILES[$field]['name'])
{
return 'empty';
}
$temp_image_path = $_FILES[$field]['tmp_name'];
$temp_image_name = $_FILES[$field]['name'];
list($iwidth, $iheight, $temp_image_type) =
getimagesize($temp_image_path);
if ($temp_image_type === NULL) {
return false;
}
elseif( $iwidth < 400 )
return 'size';
switch ($temp_image_type) {
case IMAGETYPE_GIF:
break;
case IMAGETYPE_JPEG:
break;
case IMAGETYPE_PNG:
break;
default:
return false;
}
$uploaded_image_path = UPLOADED_IMAGE_DESTINATION . $temp_image_name;
move_uploaded_file($temp_image_path, $uploaded_image_path);
$thumbnail_image_path = THUMBNAIL_IMAGE_DESTINATION .
preg_replace('{\\.[^\\.]+$}', '.jpg', $temp_image_name);
$main_image_path = MAIN_IMAGE_DESTINATION . preg_replace('{\\.[^\\.]+$}', '.jpg', $temp_image_name);
$result =
generate_image_thumbnail($uploaded_image_path,
$thumbnail_image_path,150,150
); if( $result )
$result =
generate_image_thumbnail($uploaded_image_path,$main_image_path,400,400,
true);
return $result ? array($uploaded_image_path, $thumbnail_image_path) :
false;
}
if(isset($_POST['upload'])):
$result = process_image_upload('image');
if ($result === false) {
update_option('meme_message','<div class="error" style="margin-
left:0;"><p>An error occurred while processing upload</p></div>');
} else if( $result === 'empty')
{
update_option('meme_message','<div class="error" style="margin-
left:0;"><p>Please select a Image file</p></div>');
}
elseif( $result === 'size')
{
update_option('meme_message','<div class="error" style="margin-
left:0;"><p>Image width must be greater than 400px;</p></div>');
}
else {
update_option('meme_message','<div style="margin-left:0;"
class="updated"><p>Image uploaded successfully</p></div>');
$guploaderr = false;
$count = intval(get_option('meme_image_count'));
update_option('meme_image_count', $count+1);
}
endif;
and here is some php that I know will work to rotate... but I don't know how to implement.
<?php
$image =
imagecreatefromstring(file_get_contents($_FILES['image_upload']
['tmp_name']));
$exif = exif_read_data($_FILES['image_upload']['tmp_name']);
if(!empty($exif['Orientation'])) {
switch($exif['Orientation']) {
case 8:
$image = imagerotate($image,90,0);
break;
case 3:
$image = imagerotate($image,180,0);
break;
case 6:
$image = imagerotate($image,-90,0);
break;
}
}
// $image now contains a resource with the image oriented correctly
?>

getimagesize() function not working with linux

I have this function
public static function upload($path_folder, $input_file_name) {
$photo_file = $_FILES[$input_file_name]; // FILE NAME
$photo_name = $photo_file['name']; // PHOTO NAME
$photo_tmp_name = $photo_file['tmp_name']; // TMP NAME
$photo_extension = pathinfo($photo_name, PATHINFO_EXTENSION); // EXTENSION
// soon GIFs
$rand_num = random_int(1, 3);
switch ($rand_num) {
case 1:
$hash = mb_strtoupper(Hash::create(), 'UTF-8');
break;
case 2:
$hash = mb_strtolower(Hash::create(), 'UTF-8');
break;
case 3:
$hash = str_shuffle(Hash::create());
break;
default:
$hash = Hash::create();
break;
}
$photo_with_extension = $hash . '.' . $photo_extension; // NEW FILE NAME
$factory_destination = 'photos/factory/' . $photo_with_extension; // FACTORY
if(move_uploaded_file($photo_tmp_name, $factory_destination)) {
if(file_exists($factory_destination)) {
if(
($photo_extension === 'jpg') ||
($photo_extension === 'jpeg') ||
($photo_extension === 'JPG') ||
($photo_extension === 'JPEG') ||
($photo_extension === 'png') ||
($photo_extension === 'PNG')
) {
if(
($photo_extension === 'jpg') ||
($photo_extension === 'jpeg') ||
($photo_extension === 'JPG') ||
($photo_extension === 'JPEG')
) {
if(imagecreatefromjpeg($factory_destination)) { // JPEG
$photo_create = imagecreatefromjpeg($factory_destination);
}
}
if(
($photo_extension === 'png') ||
($photo_extension === 'PNG')
) {
if(imagecreatefrompng($factory_destination)) { // PNG
$photo_create = imagecreatefrompng($factory_destination);
}
}
if(getimagesize($photo_tmp_name)) {
list($photo_width, $photo_height) = getimagesize($photo_tmp_name); // WIDTH & HEIGHT
$photo_new_width = 300; // NEW WIDTH
$photo_new_height = 300;
//$photo_new_height = ($photo_height / $photo_width) * $photo_new_width; // NEW HEIGHT
$true_color = imagecreatetruecolor($photo_new_width, $photo_new_height); // TRUE COLOR
if(imagecopyresampled($true_color, $photo_create, 0, 0, 0, 0, $photo_new_width, $photo_new_height, $photo_width, $photo_height)) {
$photo_copy = imagecopyresampled($true_color, $photo_create, 0, 0, 0, 0, $photo_new_width, $photo_new_height, $photo_width, $photo_height); // COPY
$mime = mime_content_type($factory_destination);
if(($mime === 'image/jpeg') || ($mime === 'image/png')) {
switch ($path_folder) {
case 1:
$folder = 'profile';
break;
case 2:
$folder = 'identities';
break;
default:
$folder = 'errors';
break;
}
$new_destination = 'photos/' . $folder . '/';
//$image = imagecreatefromstring(file_get_contents($photo_tmp_name));
$exif = exif_read_data($factory_destination);
if(!empty($exif['Orientation'])) {
switch($exif['Orientation']) {
case 8:
$true_color = imagerotate($true_color,90,0);
break;
case 3:
$true_color = imagerotate($true_color,180,0);
break;
case 6:
$true_color = imagerotate($true_color,-90,0);
break;
}
}
if(imagejpeg($true_color, $new_destination . $photo_with_extension, 75)) { // DESIGNATED PATHS
imagedestroy($true_color); // return
if(unlink($factory_destination)) {
return $photo_with_extension; // AUTO UPDATE ADMIN THAT THERE IS A PROBLEM
} else { return 'unlink last'; }
} else { return 'imagejpeg'; }
} else { return 'mime'; }
/*move*/
} else { return 'resampled'; }
} else { return 'get image:' . $photo_tmp_name; }
} else { return 'wrong ext'; }
} else { return 'default2.png'; }
} else { return 'move'; }
return empty($photo_with_extension) ? '' : 'false';
}
the function works upto move_uploaded_file() after that nothing is happening.
This is on production, GD enabled and compatible, Linux server. Where do you think that my codes went wrong ? This works perfectly fine on my localhost though.
To be precise, the imagejpeg() is the one that is not working
New info;
It seems that the problem occurs on getimagesize($photo_tmp_name) it returns false
Newer info:
the tmp_name that given on getimagesize() is correct when I echo it, but it returns false.
if after move_uploaded_file() func,it should be destroy the tmp_file,you could replace the tmp_file with the moved files already,as php will execute the process blocked,so that is safe to do!

Picture miniaturized in PHP - dead link

I have a php code who miniaturizes uploaded pictures by users.
This code is in the "miniature.php" file and it creates a file for each new picture.
After having uploaded the picture in another file (userform), it shows a preview (the miniature).
However, this is a dead link (I can see a little broken picture). The URL is like that :
http://www.mywebsite.com/annonce/miniature.php?pic=upload/XStmQFRY/PICTURE_UPLOADED.JPG&w_max=70&h_max=60
The url below, on the other hand, works and shows the original picture :
http://www.mywebsite.com/annonce/upload/XStmQFRY/PICTURE_UPLOADED.JPG
If you have an idea... do not hesitate!
Thank you :)
miniature.php code :
<?php
error_reporting(E_ALL ^ E_NOTICE);
$taille = getimagesize($pic);
$h_i = $taille[1];
$w_i = $taille[0];
if($h_i >$h_max)
{
$convert=$h_max/$h_i;
$h_i=$h_max;
$w_i=ceil($w_i*$convert);
}
if($w_i >$w_max)
{
$convert=$w_max/$w_i;
$w_i=$w_max;
$h_i=ceil($h_i*$convert);
} ;
$largeur = $w_i;
$hauteur = $h_i;
header("Content-Type: image/jpeg");
list($width, $height, $type, $attr) = getimagesize($pic);
if($type == "1")
{
$img_in = imagecreatefromgif($pic);
}
if($type == "2")
{
$img_in = imagecreatefromjpeg($pic);
}
if($type == "3")
{
$img_in = imagecreatefrompng($pic);
}
$img_out = imagecreatetruecolor($largeur, $hauteur);
imagecopyresampled($img_out, $img_in, 0, 0, 0, 0, imagesx($img_out), imagesy($img_out), imagesx($img_in), imagesy($img_in));
$t = imagejpeg($img_out);
echo $t;
?>
upload-file.php code :
<?php
$repdossier = $_GET['repdossier'];
$uploaddir = 'upload/'.$repdossier.'/';
$file = $uploaddir . basename($_FILES['uploadfile']['name']);
$dir2 = opendir("upload/$repdossier/");
$getpages=0;
while ($File = readdir($dir2)){
if($File != "." && $File != ".." && $File != "" )
{ $getpages++;
}
}
closedir($dir2);
$calcul = $getpages;
if( #is_file($file) )
{
echo "error2";
}
else
{
if( $calcul >= 5)
{
echo "error1";
}
else
{
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) {
echo "success";
} else {
echo "error";
}
}
}
?>
Javascript extract from all-index.php (shows the URL generated) :
if(response==="success"){
$('<li></li>').appendTo('#files').html('<img src="miniature.php?pic=upload/<?php echo $repdossier; ?>/'+file+'&w_max=70&h_max=60" height="60" width="70" alt="" /><br />').addClass('success');
}
You edited the question, removed the buggy code and put in some unrelated Javascript.
The error is here:
<?php
error_reporting(E_ALL ^ E_NOTICE);
$taille = getimagesize("$pic");
$pic must be a valid path to an existing picture. As of now, the variable is empty (undefined).

How do I modify this to upload multiple files?

My upload code is this. I submit the image to it with postdata. I want to make the file select box accept multiple picutes, and have it work on the backend. I can get the header location to work just fine on my own, but using an array of files has proved to be difficult, even though I've spent hours on stack overflow and google. I'd love it if somebody could show me how to do it.
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$browse = $_POST["browse"];
preg_match('/\.([a-zA-Z]+?)$/', $_FILES['userfile']['name'], $matches);
if(in_array(strtolower($matches[1]), $accepted)) {
if($_FILES['userfile']['size'] <= $maxsize) {
$newname = md5_file($_FILES['userfile']['tmp_name']).'.'.$matches[1];
$browse = $_POST["browse"];
if ($browse == "1") {
$filedir = 'img';
} else if ($browse == "2") {
$filedir = 'zega';
} else if ($browse == "3") {
$filedir = 'noimg';
} else if ($browse == "4") {
$filedir = 'adult';
} else if ($browse == "5") {
$filedir = 'temp';
} else {
$filedir = 'noimg';
}
move_uploaded_file($_FILES['userfile']['tmp_name'], $filedir.'/'.$newname);
$path = $filedir.'/'.$newname;
if (strpos($path,'jpg') !== false){
$img = imagecreatefromjpeg ($path);
imagejpeg ($img, $path, 100);
imagedestroy ($img);
} else if (strpos($path,'gif') !== false){
$img = imagecreatefromgif ($path);
imagegif ($img, $path, 100);
imagedestroy ($img);
} else if (strpos($path,'bmp') !== false){
$img = imagecreatefrombmp ($path);
imagebmp ($img, $path, 100);
imagedestroy ($img);
}
header("Location: index.php?p=uploaded&img=$newname");
} else
header("Location: index.php?p=error&num=2");
} else
header("Location: index.php?p=error&num=1");
}
?>
foreach($_FILES as $key_file=>$file_info){
//your code here instead $_FILES['userfile']['tmp_name'] use $file_info['tmp_name']
}
i wrote a class for uploads sometimes ago.
this class has ability to upload mutiple files at the same time(such as picture .etc).
it also has other ability such as :
-if you upload mutiple files with the same name it will automatically change their name
-you can add permitted types
-set maximum size of uploaded files
...
class Upload {
protected $_uploaded = array();
protected $_destination_upload_folder;
//Constraint
protected $_max_upload_size = 512000;
protected $_permitted_files = array('image/gif', 'image/png', 'image/jpg', 'image/jpeg', 'image/pjpeg');
protected $_error_messages = array();
protected $_renamed_file = false;
public function __construct($input_upload_path) {
if(!is_dir($input_upload_path) || !is_writable($input_upload_path)){
throw new Exception("$input_upload_path must be a valid,writable path!");
}
$this->_destination_upload_folder = $input_upload_path;
$this->_uploaded = $_FILES;
}
protected function checkError($fileName, $error){
switch ($error) {
case 0:
return true;
case 1:
case 2:
$this->_error_messages[] = "$fileName exceeds maximum file size : "
.$this->getMaxSize();
return true;
case 3:
$this->_error_messages[] = "Error while uploading $fileName.please try again.";
return false;
case 4:
$this->_error_messages[] = "No file selected.";
return false;
default:
$this->_error_messages[] = "System Error uploading $fileName.Please contact administrator.";
return false;
return false;
}
}
protected function checkSize($fileName, $size){
if($size == 0){
return false;
}else if($size > $this->_max_upload_size){
$this->_error_messages[] = "$fileName exceeds maximum size : ".
$this->_max_upload_size;
return false;
}else{
return true;
}
}
protected function checkType($fileName, $type){
if(!in_array($type, $this->_permitted_files)){
$this->_error_messages[] = 'This type of file is not allowed for uploading '
.'.please upload permitted files.';
return false;
}else{
return true;
}
}
public function checkName($input_file_name, $overwrite)
{
$input_file_name_without_spaces = str_replace(' ', '_', $input_file_name);
if($input_file_name_without_spaces != $input_file_name){
$this->_renamed_file = true;
}
if(!$overwrite){
$all_files_in_upload_directory = scandir($this->_destination_upload_folder);
if(in_array($input_file_name_without_spaces, $all_files_in_upload_directory)){
$dot_position = strrpos($input_file_name_without_spaces, '.');
if($dot_position){
$base = substr($input_file_name_without_spaces, 0, $dot_position);
$extension = substr($input_file_name_without_spaces, $dot_position);
}else{
$base = substr($input_file_name_without_spaces);
$extension = '';
}
$i = 1;
do{
$input_file_name_without_spaces = $base.'_'.$i++.$extension;
}while(in_array($input_file_name_without_spaces, $all_files_in_upload_directory));
$this->_renamed_file = true;
}
}
return $input_file_name_without_spaces;
}
protected function getMaxSize(){
return number_format(($this->_max_upload_size)/1024, 1).'kb';
}
protected function isValidMime($types)
{
$also_valid_mimes = array('application/pdf', 'text/plain', 'text/rtf');
$all_valid_mimes = array_merge($this->_permitted_files, $also_valid_mimes);
foreach($types as $type){
if(!in_array($type, $all_valid_mimes)){
throw new Exception("$type is not a valid permitted mime type!");
}
}
}
public function addPermittedType($input_type_name)
{
$input_type_name_array = (array)$input_type_name;
$this->isValidMime($input_type_name_array);
$this->_permitted_files = array_merge($this->_permitted_files, $input_type_name_array);
}
protected function processFile($fileName, $error, $size, $type, $tmp_name, $overwrite)
{
$check_upload_error = $this->checkError($fileName, $error);
if($check_upload_error){
$check_uploaded_file_type = $this->checkType($fileName, $type);
$check_uploaded_file_size = $this->checkSize($fileName, $size);
if($check_uploaded_file_type && $check_uploaded_file_size){
$new_uploaded_file_name = $this->checkName($fileName, $overwrite);
$upload_result = move_uploaded_file($tmp_name, $this->_destination_upload_folder.$new_uploaded_file_name);
if($upload_result){
$messages = $new_uploaded_file_name.' uploaded successfully! <br >';
if($this->_renamed_file){
$messages .= ' and renamed successfully!';
}
$this->_error_messages[] = $messages;
} else {
$this->_error_messages[] = 'Could`nt upload '.$fileName;
}
}
}
}
public function move($overwrite = FALSE){
$file = current($this->_uploaded);
if(is_array($file['name'])){
foreach($file['name'] as $index => $filename){
$this->_renamed_file = false;
$this->processFile($filename, $file['error'][$index],
$file['size'][$index], $file['type'][$index], $file['tmp_name'][$index], $overwrite);
}
}else{
$this->processFile($file['filename'], $file['error'], $file['size'], $file['type']
, $file['tmp_name'], $overwrite);
}
}
public function getErrorMessages(){
return $this->_error_messages;
}
public function setMaxSize($new_upload_size)
{
if(!is_numeric($new_upload_size) || $new_upload_size <= 0){
throw new Exception("new maximum upload size must a number!");
}
$this->_max_upload_size = (int)$new_upload_size;
}
}
$max_upload_size = 1024 * 1024;
if(isset($_POST['upload_button'])){
$destination_upload_folder = 'destination of upload folder here....';
require_once 'Upload class filename...';
try{
$upload = new Upload($destination_upload_folder);
$upload->setMaxSize($max_upload_size);
$upload->addPermittedType('application/pdf');
$upload->move(true);
$result = $upload->getErrorMessages();
}catch(Exception $e){
echo $e->getMessage();
}
}

Limiting the checking condition while uploading SWF files

I am creating an application of uploading swf files in a folder using PHP.
My script is all working except for the first if condition where I'm checking whether the extension is swf or not, but I seems to have some error.
I'm not sure whether video/swf is a valid checking parameter for SWF files or not. My full script is below. I'm checking the size of the SWF using getimagesize(). Some people may wonder that getimagesize works for image, but I saw some examples where getimagesize() has been used for getting size of SWF files.
It's giving me the message "invalid swf file", that means its not satisfying the first checking condition at all.
<?php
foreach($_FILES['item_swf']['tmp_name'] as $key=>$val)
{
list($width, $height) = getimagesize($_FILES['item_swf']['tmp_name'][$key]);
if (( ($_FILES["item_swf"]["type"][$key] == "video/swf") || ($_FILES["item_swf"]["type"][$key] == "video/SWF") )
&& ($_FILES["item_swf"]["size"][$key] < 800000))
{
if ($_FILES["item_swf"]["error"][$key] > 0)
{
echo "Error: " . $_FILES["item_swf"]["error"][$key] . "<br />";
}
else if($width==1000 && $height==328)
{
if (file_exists('../../swf_folder/header_swf/' . $_FILES["item_swf"]["name"]))
{
echo $_FILES["item_swf"]["name"][$key] . " already exists. ";
}
else
{
move_uploaded_file($val, '../../swf_folder/header_swf/'.$_FILES['item_swf']['name'][$key]);
echo "done";
}
}
else
{
echo "size doest permit";
}
}
else
{
echo "Not a valid swf file::";
}
}
?>
The line given below
move_uploaded_file($val, '../../swf_folder/header_swf/'.$_FILES['item_swf']['name'][$key]);
is working perfectly as it is uploading files to the dedicated folder, it somehow seems that the checking parameters for SWF only files are not set properly.
Edit
I got my answer. Instead of using video/swf I need to use application/x-shockwave-flash.
So the ultimate code will be:
<?php
foreach($_FILES['item_swf']['tmp_name'] as $key=>$val)
{
list($width, $height) = getimagesize($_FILES['item_swf']['tmp_name'][$key]);
if (($_FILES["item_swf"]["type"][$key] == "application/x-shockwave-flash")
&& ($_FILES["item_swf"]["size"][$key] < 800000))
{
if ($_FILES["item_swf"]["error"][$key] > 0)
{
echo "Error: " . $_FILES["item_swf"]["error"][$key] . "<br />";
}
else if($width==1000 && $height==328)
{
if (file_exists('../../swf_folder/header_swf/' . $_FILES["item_swf"]["name"]))
{
echo $_FILES["item_swf"]["name"][$key] . " already exists. ";
}
else
{
move_uploaded_file($val, '../../swf_folder/header_swf/'.$_FILES['item_swf']['name'][$key]);
echo "done";
}
}
else
{
echo "size doest permit";
}
}
else
{
echo "Not a valid swf file::";
}
}
?>
you can try
$savePath = "PATH_TO_SAVE";
$errors = array ();
$output = array ();
//
if (isset ( $_FILES ['item_swf'])) {
foreach ( $_FILES ['item_swf'] ['tmp_name'] as $key => $val ) {
$fileName = $_FILES ['item_swf'] ['name'] [$key];
$fileSize = $_FILES ['item_swf'] ['size'] [$key];
$fileTemp = $_FILES ['item_swf'] ['tmp_name'] [$key];
$fileExtention = pathinfo ( $fileName, PATHINFO_EXTENSION );
$fileExtention = strtolower ( $fileExtention );
if ($fileExtention != ".swf") {
$errors [$fileName] [] = "Invalid File Extention";
continue;
}
if ($fileSize > 800000) {
$errors [$fileName] [] = "File Too large";
continue;
}
list ( $width, $height ) = getimagesize ( $fileTemp );
if ($width != 1000 && $height != 328) {
$errors [$fileName] [] = "Wrong File dimention ";
continue;
}
if (file_exists ( $savePath . DIRECTORY_SEPARATOR . $fileName )) {
$errors [$fileName] [] = "File Exist";
continue;
}
if(!is_writable($savePath ))
{
$errors [$fileName] [] = "File Destination not writeable";
}
if(count($errors [$fileName]) == 0)
{
if(#move_uploaded_file ( $fileTemp, $savePath . DIRECTORY_SEPARATOR . $fileName))
{
$output[$fileName] == "OK" ;
}
else
{
$errors [$fileName] [] = "Error Saving File";
}
}
}
var_dump($errors, $output);
}
Let me know if you have any more challenge
ok, i got my answer....
instead of using video/swf i need to use application/x-shockwave-flash
so the ultimate code will be
<?php
foreach($_FILES['item_swf']['tmp_name'] as $key=>$val)
{
list($width, $height) = getimagesize($_FILES['item_swf']['tmp_name'][$key]);
if (( ($_FILES["item_swf"]["type"][$key] == "application/x-shockwave-flash") || ($_FILES["item_swf"]["type"][$key] == "video/SWF") )
&& ($_FILES["item_swf"]["size"][$key] < 800000))
{
if ($_FILES["item_swf"]["error"][$key] > 0)
{
echo "Error: " . $_FILES["item_swf"]["error"][$key] . "<br />";
}
else if($width==1000 && $height==328)
{
if (file_exists('../../swf_folder/header_swf/' . $_FILES["item_swf"]["name"]))
{
echo $_FILES["item_swf"]["name"][$key] . " already exists. ";
}
else
{
move_uploaded_file($val, '../../swf_folder/header_swf/'.$_FILES['item_swf']['name'][$key]);
echo "done";
}
}
else
{
echo "size doest permit";
}
}
else
{
echo "Not a valid swf file::";
}
}
?>

Categories