I have been over and over this but I can not find why it is giving this error. Parse error: syntax error, unexpected $end in /home/valerie2/public_html/elinkswap/snorris/file.php on line 78. Maybe if there was more eyes on it maybe be able to find where I didnt do something right. Thanks for looking.
<?php
session_start();
include "connect.php";
if ($_POST["submit"])
{
//Coding
if($_SESSION["name"])
{
//variables
$name = $_FILES["file"]["name"];
$type = $_FILES["file"]["type"];
$size = $_FILES["file"]["size"];
$tmp_name = $_FILES["file"]["tmp_name"];
$error = $_FILES["file"]["error"];
if ($type =="image/jpeg" || $type =="image/gif")
{
if ($size >1100000 && $size <1700000)
{
if($error > 0)
{
echo "Error!!!!!!".$error;
}
else
{
if(file_exists("upload/".$name))
{
echo $name." already exists.";
}
else
{
$location ="upload/".$name;
move_uploaded_file($tmp_name,$location);
$user = $_SESSION["name"];
$sqlcode = mysql_query("INSERT INTO imageupload (id,user,location) VALUES ('','$user','$location')");
echo "<a href='$location'>Click here to view your image.</a>";
}
}
}
else
{
echo "Please check the size of your File..";
}
}
else
{
echo "Invalid file format.";
}
?>
Line 78 is just before the ?>
It is difficult to follow with so many nested IF staements, but it looks like you have failed to close 2 IFs (if submit and if name)
Change you code to:
<?php
session_start();
include "connect.php";
if ( $_POST[ "submit" ] ) {
if ( $_SESSION[ "name" ] ) {
$name = $_FILES[ "file" ][ "name" ];
$type = $_FILES[ "file" ][ "type" ];
$size = $_FILES[ "file" ][ "size" ];
$tmp_name = $_FILES[ "file" ][ "tmp_name" ];
$error = $_FILES[ "file" ][ "error" ];
if ( $type == "image/jpeg" || $type == "image/gif" ) {
if ( $size > 1100000 && $size < 1700000 ) {
if ( $error > 0 ) {
echo "Error!!!!!!" . $error;
} else {
if ( file_exists( "upload/" . $name ) ) {
echo $name . " already exists.";
}
}
} else {
$location = "upload/" . $name;
move_uploaded_file( $tmp_name , $location );
$user = $_SESSION[ "name" ];
$sqlcode = mysql_query( "INSERT INTO imageupload (id,user,location) VALUES ('','$user','$location')" );
echo "<a href='$location'>Click here to view your image.</a>";
}
}
} else {
echo "Please check the size of your File..";
}
} else {
echo "Invalid file format.";
}
?>
And please use the practice to indent your code, it will be a quick and easy way to correct these errors.
Change this:
if ($size >1100000 && $size <1700000)
{
if($error > 0)
{
echo "Error!!!!!!".$error;
}
to....
if ($size >1100000 && $size <1700000)
{
if($error > 0)
{
echo "Error!!!!!!".$error;
}
}
Related
Hi I have a file upload function. Controls file size and file type. If the file is in PDF format and is smaller than 10MB, everything works as it should.
If the file is not PDF, it should show me the message: "ERROR: You can just upload PDF files." but no message.
If the file size is larger than 10MB, it should show me the message: "ERROR: Max file size 10MB." but no message.
If the file is PDF but larger than 10MB, it shows me: "ERROR: All fields must be filled."
What is wrong with my code?
Function :
<?php
function file_create($file) {
if(isset($file)){
$errors = array();
$target_dir = "../files/";
$file_name = uniqid();
$file_size = $file['size'];
$file_tmp = $file['tmp_name'];
$file_type = $file['type'];
$file_ext = strtolower(end(explode('.',$file['name'])));
if($file_type != "application/pdf") {
$error = "ERROR : You can upload just PDF files.";
array_push($errors, $error);
}
if($file_size > 1024*1024*10) {
$error = "ERROR : Max file size 10MB.";
array_push($errors, $error);
}
if(empty($errors) == true) {
move_uploaded_file($file_tmp,$target_dir.$file_name.".".$file_ext);
$errors['status'] = true;
$errors['patch'] = substr($target_dir.$file_name.".".$file_ext, 3);
} else {
$errors['status'] = false;
}
return $errors;
}
}
?>
Another File :
<?php
$errors = array();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$notice_title = secured_post("notice-title");
$notice_content = secured_post("notice-content");
// if there is empty field in form.
if (multi_empty($notice_title, $notice_content)) {
// if a file submitted.
if (isset($_FILES['notice-file'])) {
$notice_file = $_FILES['notice-file'];
// upload the file.
$upload = file_create($notice_file);
if ($upload['status'] == false) {
$size = count($upload);
for ($i=0; $i < $size; $i++) {
array_push($errors, $upload[$i]);
}
}
notice_create($conn, $notice_title, $notice_content, $upload['patch']);
} else {
notice_create($conn, $notice_title, $notice_content);
}
} else {
$error = "ERROR : All fields must be filled.";
array_push($errors, $error);
}
}
if ($errors) {
foreach ($errors as $error) {
echo "<div class='error'>".$error."</div></br>";
}
}
?>
Here's the problem. If your file is larger than 10MB then it can take some time to upload the file so you have to check if the $_FILES array is empty or not.
Try this:
<?php
$errors = array();
if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_FILES)) { //I've made changes to this line
$notice_title = secured_post("notice-title");
$notice_content = secured_post("notice-content");
// if there is empty field in form.
if (multi_empty($notice_title, $notice_content)) {
// if a file submitted.
if (isset($_FILES['notice-file'])) {
$notice_file = $_FILES['notice-file'];
// upload the file.
$upload = file_create($notice_file);
if ($upload['status'] == false) {
$size = count($upload);
for ($i=0; $i < $size; $i++) {
array_push($errors, $upload[$i]);
}
}
notice_create($conn, $notice_title, $notice_content, $upload['patch']);
} else {
notice_create($conn, $notice_title, $notice_content);
}
} else {
$error = "ERROR : All fields must be filled.";
array_push($errors, $error);
}
}
if ($errors) {
foreach ($errors as $error) {
echo "<div class='error'>".$error."</div></br>";
}
}
?>
And:
<?php
function file_create($file) {
if(!empty($file)){ //I've made changes to this line
$errors = array();
$target_dir = "../files/";
$file_name = uniqid();
$file_size = $file['size'];
$file_tmp = $file['tmp_name'];
$file_type = $file['type'];
$file_ext = strtolower(end(explode('.',$file['name'])));
if($file_type != "application/pdf" || $file_ext != ".pdf") { //I've made changes to this line
$error = "ERROR : You can upload just PDF files.";
array_push($errors, $error);
}
if($file_size > (1024*1024*10)) {
$error = "ERROR : Max file size 10MB.";
array_push($errors, $error);
}
if(empty($errors) == true) {
move_uploaded_file($file_tmp,$target_dir.$file_name.".".$file_ext);
$errors['status'] = true;
$errors['patch'] = substr($target_dir.$file_name.".".$file_ext, 3);
} else {
$errors['status'] = false;
}
return $errors;
}
}
?>
Note: The $_FILES array can be set and empty at the same time so isset() can't help you here.
How to an add user_id ($_POST['pk']) at the beginning of the filename when I upload an image to server with the below function update_customer().
With this I can easily discover the correct files of a specific user.
Result should be:
filename = $_POST['pk'].'-'.$_POST['name']
function update_customer() {
if(isset($_POST['name']) && isset($_POST['pk'])) {
//print_r($_FILES['image']);exit;
$filename = '';
if(isset($_FILES['image']) && $_FILES['image']['tmp_name'] && $_FILES['image']['error'] == 0) {
$filename = $_FILES['image']['name'];
$upload_dir = $_SERVER['DOCUMENT_ROOT'].'/wp-content/uploads/agent_company_logos/';
$wp_filetype = wp_check_filetype_and_ext( $_FILES['image']['tmp_name'], $_FILES['image']['name'] );
if($wp_filetype['proper_filename'])
$_FILES['image']['name'] = $wp_filetype['proper_filename'];
if ( ( !$wp_filetype['type'] || !$wp_filetype['ext'] ) ) {
$arrErrors['file'] = __('File type not allowed', 'agent-plugin');
}
else {
move_uploaded_file($_FILES['image']['tmp_name'], $upload_dir.$_FILES['image']['name']);
}
if(!empty($arrErrors) && count($arrErrors) == 0) {
die (json_encode(array('file' => agent_get_user_file_path($_FILES['image']['name']), 'caption' => '', 'status' => 1)));
}
//echo $_FILES['image']['name'];
}
$updated = $GLOBALS['wpdb']->update($GLOBALS['wpdb']->prefix.'agent_customer', array('company_logo' => $filename), array('user_id' => $_POST['pk']));
$dir = wp_upload_dir();
echo $dir['baseurl'] . '/agent_company_logos/'.$filename; exit(0);
}
echo 0;
die();
}
you can use
$basname = $_POST['pk'].basename($file);
Apologies, but couldn't find an answer to this already...
I have some PHP code that hits an error, which I echo and save to an array:
echo "File is not an image.";
$errors[] = "File is not an image";
The array is defined earlier:
$errors = array();
When I debug my web page, I can see the echo (so I know it's hitting that error) but the array is empty...screenshot below:
screenshot of web page
Any idea what I'm doing wrong? Or how to debug further?
Thanks!
Simon
EDIT: I noticed the array was declared twice. Removed that, no change.
Full code below
<?php
class BanditquotecustomformModuleFrontController extends ModuleFrontController
{
public function initContent()
{
$varCountry = '';
$varRemarks = '';
$varContactEmail = '';
$varCustomerName = '';
$varPhone = '';
$varUrgency = '';
$sql = '';
$user_id ='';
/* For when I get this working!
$id_lang = Context::getContext()->language->id;
$category = Category::searchByName($id_lang,"personalised",true);*/
/*parent::initContent();*/
if ($this->context->customer->isLogged())
{
$this->setTemplate('customform.tpl');
$custfirstname = $this->context->customer->firstname;
$custlastname = $this->context->customer->lastname;
$custemail = $this->context->customer->email;
$this->context->smarty->assign('firstname', $custfirstname);
$this->context->smarty->assign('lastname', $custlastname);
$this->context->smarty->assign('customer_email', $custemail);
parent::initContent();
}
else
{
Tools::redirect('index.php?controller=authentication&back='.urlencode($this->context->link->getModuleLink('banditquote', 'customform')));
}
}
/* adds a new product for every quote */
private function addProduct($LastId)
{
$reference = 'CUST'.$LastId;
$name = $reference;
$product = new Product();
$languages=Language::getLanguages();
foreach($languages as $lang){
$product->name[$lang['id_lang']]=$name;
$product->link_rewrite[$lang['id_lang']]=$name;
$product->description[$lang['id_lang']]=$name;
}
$product->reference=$reference;
$product->active='1';
$product->available_for_order='1';
$product->is_virtual='1';
/* add product to category */
$product->id_category='2';
$product->id_category_default='2';
try{
$product->save();
} catch (PrestaShopException $e){
echo $e->displayMessage();
}
$product->addToCategories(array(2));
$product->save();
$prod_shopupdate = Db::getInstance()->Execute('
UPDATE `'.pSQL(_DB_PREFIX_).'product_shop`
SET `active` = "1",`available_for_order` = "1"
WHERE `id_product` = "'.((int)$product->id).'"');
return $product->id;
}
/* checking attachment */
private function checkImage()
{
$target_dir = '_THEME_PROD_PIC_DIR_';
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 0;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
$errors[] = $this->module->l('File is an image', 'customform');
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image";
$errors[] = "File is not an image";
$uploadOk = 0;
}
// Check if file already exists
if (file_exists($target_file)) {
$errors[] = $this->module->l('Sorry, file already exists', 'customform');
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
$errors[] = $this->module->l('Sorry, your file is too large', 'customform');
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
$errors[] = $this->module->l('Sorry, only JPG, JPEG, PNG & GIF files are allowed', 'customform');
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
$errors[] = $this->module->l('Sorry, your file was not uploaded', 'customform');
// if everything is ok, try to upload file
}
else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
}
else {
$errors[] = $this->module->l('Sorry, there was an error uploading your file', 'customform');
}
}
return $uploadOk;
}
public function postProcess()
{
if (Tools::isSubmit('submit'))
{
$errors = array();
$failed = false;
$varUserId = (int)$this->context->customer->id;
$varRemarks = Tools::getValue('formRemarks');
$newRemarks = str_replace("'","''", $varRemarks);
$varCountry = Tools::getValue('formCountry');
$varContactEmail = Tools::getValue('formContactEmail');
$varCustomerName = Tools::getValue('formCustomerName');
$varPhone = Tools::getValue('formPhone');
$varUrgency = Tools::getValue('formUrgency');
if (empty($varRemarks))
{
$errors[] = $this->module->l('The message cannot be blank.', 'customform');
//d($errors);
}
else
{
$sql = "INSERT INTO `ps_quotes` (`quote_destin`,`quote_remarks`,`quote_email`,`quote_submitter_name`,`quote_phone`,`quote_urg`,`quote_user_id`)
VALUES('{$varCountry}','{$newRemarks}','{$varContactEmail}','{$varCustomerName}','{$varPhone}','{$varUrgency}','{$varUserId}');";
if (!Db::getInstance()->execute($sql))
{
die('Error creating Custom Order - Please contact admin#banditbirds.co.uk');
}
$quoteid = Db::getInstance()->Insert_ID();
$prod_id = $this->addProduct(Db::getInstance()->Insert_ID());
if ($prod_id == null )
{
die('Error creating Custom Product for Custom Order - Please contact admin#banditbirds.co.uk');
}
$updatesql = "UPDATE `ps_quotes` SET `quote_product_link` = $prod_id WHERE `quote_id` = $quoteid;";
Db::getInstance()->execute($updatesql);
//Check the uploaded attachment - if there
if ( $this->checkImage() )
{
// add ps_attachment
// link ps_attachment to product with ps_product_attachment
}
else
{
$this->context->smarty->assign('errors', $errors);
$failed = true;
d($errors);
}
//Mailing
$confirmation1 = '';
$template = 'banditquote';
$template_owner = 'banditquote_owner';
$template_vars = array(
'{banditquote_contactaddress}' => '',
'{banditquote_contacttown}' => '',
'{shop_url}' => Tools::getShopDomain(true),
/* in case we need to check ssl $this->ssl_enable ? Tools::getShopDomainSsl(true) : Tools::getShopDomain(true);*/
'{remarks}' => $varRemarks,
'{shipping_destination}' => $varCountry,
'{phone}' => $varPhone,
'{name_cust}' => $varCustomerName,
'{shipping_quantity}' => '',
'{paypal}' => '',
'{first_order}' => '',
'{urgency}' => $varUrgency,
'{language}' => (int)$this->context->language->id,
'{webmaster}' => 'admin#banditbirds.co.uk',
'{email}' => $varContactEmail,
'{shop_name}' => Configuration::get('PS_SHOP_NAME'),
'{owner_email}' => Configuration::get('PS_SHOP_EMAIL'));
$language = (int)$this->context->language->id;
$maildir = '/home/banditbi/public_html/modules/banditquote/mails/1.5/';
if ((Mail::Send($language, $template, Configuration::get('PS_SHOP_NAME'), $template_vars, $varContactEmail, null, null, null, null, null, $maildir,false,null)) &&
(Mail::Send($language, $template_owner, Configuration::get('PS_SHOP_NAME'), $template_vars, 'admin#banditbirds.co.uk', null, null, null, null, null, $maildir,false,null)))
$this->context->smarty->assign('confirmation1', 1);
else
{
if (is_null($confirmation1))
{
$this->_html .= '<div style="background:#F00; padding:5px; border:thin; border-color:#030; text-align:center">'.$this->l('CAPTCHA Error, please go back and try once more.').'</div><br />';
return $this->_html;
}
}
if( !$failed )
{
Tools::redirect('index.php');
}
}
$this->context->smarty->assign(array(
'id_customer' => (int)$this->context->customer->id,
'errors' => $errors,
'form_link' => $errors,
));
$this->setTemplate('customform.tpl');
}
}
}
?>
Make sure you are defining the array before attempting to store values into it.
$errors = array();
$errors[] = 'File is not an image';
Do not try to redefine the array after you add items to this array. Otherwise, you will reset the array effectively removing any items previously added.
I want the user to be able to upload a profile picture that is named after his username, so I can easily call it afterwards. The problem is, no file is saved at the desired folder. The folder name is "profilePictures" and it's empty when there should be a picture inside called by the username of the user. I've tried to fix it but no luck. What am I doing wrong ?
Code:
<?php
class User {
public function __construct( $username, $password, $passwordRepeat, $email, $firstName, $familyName, $age, $sex, $question, $answer, $car, $profilePicture ) {
$this->username = $username;
$this->password = $password;
$this->passwordRepeat = $passwordRepeat;
$this->email = $email;
$this->firstName = $firstName;
$this->familyName = $familyName;
$this->age = $age;
$this->sex = $sex;
$this->question = $question;
$this->answer = $answer;
$this->car = $car;
$this->profilePicture = $profilePicture;
}
public function savePicture() {
if ( isset( $_POST["register_new"] ) ) {
$profiles = "profiles/$this->username.txt";
if ( $this->password !== $this->passwordRepeat ) {
} else if ( file_exists( $profiles ) ) {
} else if ( $this->age < 18 ) {
} else {
$pictureDir = "profilePictures/";
$pictureFile = $pictureDir . basename(["profilePicture"]["name"][ $this->username ] );
$pictureTemp = $_FILES["profilePicture"]["name"][ $this->username ];
$pictureType = pathinfo( $pictureFile, PATHINFO_EXTENSION );
$uploadFile = 1;
$check = getimagesize( $pictureTemp );
if ( $check !== false ) {
$uploadFile = 1;
} else {
require "register.html";
echo "<p>File is not an image</p>";
$uploadFile = 0;
}
/*
if (file_exists($pictureFile)) {
echo "<p>File already exists</p>";
}
*/
if ( $_FILES["profilePicture"]["size"] > 200000 ) {
echo "File is too large! We accept files that are less than 2 MB";
$uploadFile = 0;
}
if ($pictureType != "jpg" && $pictureType != "png" && $pictureType != "jpeg" && $pictureType != "gif") {
echo "<p>Sorry, only JPG, JPEG, PNG & GIF files are allowed.</p>";
$uploadFile = 1;
}
if ( $uploadFile == 0 ) {
echo "<p>File was not uploaded</p>";
} else {
move_uploaded_file( $pictureTemp, $pictureFile );
}
}
}
}
public function saveUser() {
if ( isset( $_POST["register_new"] ) ) {
$profiles = "profiles/$this->username.txt";
if ( $this->password !== $this->passwordRepeat ) {
require "register.html";
echo "<p>Password does not match! Please try again</p>";
} else if ( file_exists( $profiles ) ) {
require "register.html";
echo "<p>Username already exists!</p>";
} else if ( $this->age < 18 ) {
require "register.html";
echo "<p>You must be over 18 to use this site</p>";
} else {
$fp = fopen( $profiles, "a+" );
$save = $this->username . " , " . $this->password . " , " . $this->email . " , " . $this->firstName . " , " . $this->familyName . " , " . $this->age . " , " . $this->sex . " , " . $this->question . " , " . $this->answer . " , " . $this->car;
fwrite( $fp, $save );
echo "<p>Successfully registered! Click <a href=index.html>HERE</a> to go back to the login window.</p>";
}
}
}
}
$user = new User( ( $_POST["username_register"] ), ( $_POST["password_register"] ), ( $_POST["password_repeat"] ), ( $_POST["email_register"] ), ( $_POST ["first_name_register"] ), ( $_POST ["last_name_register"] ), ( $_POST["age_register"] ), ( $_POST ["sex_register"] ), ( $_POST ["question_register"] ), ( $_POST ["answer_register"] ), ( $_POST["car_register"] ), ($_POST["profilePicture"]) );
$user->saveUser();
$user->savePicture();
First make sure that you have write permission on the profilePictures map. Assuming you have permission i think it fails on this two lines:
$pictureFile = $pictureDir . basename(["profilePicture"]["name"][ $this->username ] );
$pictureTemp = $_FILES["profilePicture"]["name"][ $this->username ];
Try this instead of the 2 lines above:
//Do not add the username here, because it isn't defined anywhere.
//Also you didn't define $_FILES here, and basedir isn't neccessary since "name" only contains the filename
$pictureFile = $pictureDir . $_FILES["profilePicture"]["name"];
//To get the current picture use tmp_name
$pictureTemp = $_FILES["profilePicture"]["tmp_name"];
The function will become like this:
public function savePicture() {
if ( isset( $_POST["register_new"] ) ) {
$profiles = "profiles/$this->username.txt";
if ( $this->password !== $this->passwordRepeat ) {
} else if ( file_exists( $profiles ) ) {
} else if ( $this->age < 18 ) {
} else {
$pictureDir = "profilePictures/";
//Do not add the username here, because it isn't defined anywhere.
//Also you didn't define $_FILES here, and basedir isn't neccessary since "name" only contains the filename
$pictureFile = $pictureDir . $_FILES["profilePicture"]["name"];
//To get the current picture use tmp_name
$pictureTemp = $_FILES["profilePicture"]["tmp_name"];
$pictureType = pathinfo( $pictureFile, PATHINFO_EXTENSION );
$uploadFile = 1;
$check = getimagesize( $pictureTemp );
if ( $check !== false ) {
$uploadFile = 1;
} else {
require "register.html";
echo "<p>File is not an image</p>";
$uploadFile = 0;
}
/*
if (file_exists($pictureFile)) {
echo "<p>File already exists</p>";
}
*/
if ( $_FILES["profilePicture"]["size"] > 200000 ) {
echo "File is too large! We accept files that are less than 2 MB";
$uploadFile = 0;
}
if ($pictureType != "jpg" && $pictureType != "png" && $pictureType != "jpeg" && $pictureType != "gif") {
echo "<p>Sorry, only JPG, JPEG, PNG & GIF files are allowed.</p>";
$uploadFile = 1;
}
if ( $uploadFile == 0 ) {
echo "<p>File was not uploaded</p>";
} else {
move_uploaded_file( $pictureTemp, $pictureFile );
}
}
}
}
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::";
}
}
?>