php uploading file (powerpoint) - php

I'm using these codes to upload images and then I tried it to upload CSV files. These codes worked for both uploading images and CSV files, but it won't work in uploading powerpoint files. What am I missing here?
<?php if (isset($_POST["calendarformat"])){
$calendarfilename = $_POST['calendarfilename'];
$calendarfile = $_FILES['calendarfile']['name'];
$calendarlocation = "calendar/".$calendarfile;
move_uploaded_file($_FILES['calendarfile']['tmp_name'],$calendarlocation);
$quer_calendar = "INSERT into calendar (name,format,path) values ('$calendarfilename','$calendarfile','$calendarlocation')";
$quer1_calendar = mysqli_query($con,$quer_calendar);
if ($quer1_calendar==true)
{
echo "<script>alert('Upload Success');</script>";
}
else {
echo "<script>alert('Upload Failed');</script>";
} }?>
This is the html form:
<form method="POST" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<h4><input type="file" name="calendarfile"/></h4>
<h4><input type="text" name="calendarfilename" placeholder="File Name"/></h4>
<button type="submit" name="calendarformat" class="btn">Upload Calendar</button>
</form>

Try add this to your form:
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />

<form method="POST" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<h4><input type="file" name="calendarfile"/></h4>
<h4><input type="text" name="calendarfilename" placeholder="File Name"/></h4>
<button type="submit" name="calendarformat" class="btn">Upload Calendar</button>
</form>
This is my form, I already added the <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
The PPT file is already saved into my database, but it doesn't went to the location folder which is the calendar folder.

Related

Upload files with multiple inputs

I have a form where i want to upload files with multiple inputs.My form looks like:
<form action="" method="post">
<input type="file" name="tax" />
<input type="file" name="ta" />
<input type="submit" name="submit" />
</form>
I do not know how to process this form..
You form doesn't work until you don't include 'enctype="multipart/form-data"', because it is necessary to use input type file.
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="tax" />
<input type="file" name="ta" />
<input type="submit" name="submit" />
</form>
Now browse the file and submit the form. You will get all file data inside $_FILES. so to check what you get inside the file data, you can use :
echo '<pre>';
print_r($_FILES)
I'm not sure whether you have gone through the tutorials before, however below is the code which will help you to process it.
<form action="upload_file.php" method="post" enctype="multipart/form-data">
<input type="file" name="tax" />
<input type="file" name="ta" />
<input type="submit" name="submit" />
</form>
If you upload the file, you can get the files from,
$_FILES global array, i.e. $_FILES['tax'] and $_FILES['ta'].
More info can be found on php.net
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="tax" />
<input type="file" name="ta" />
<input type="submit" name="submit" />
</form>
<?php
//print_r($_POST);
if(isset($_POST['submit'])){
$name = $_FILES['tax']['name'];
$name1 = $_FILES['ta']['name'];
$temp_name = $_FILES['tax']['tmp_name'];
$temp_name1 = $_FILES['ta']['tmp_name'];
var_dump($_FILES);
if(isset($name)){
if(!empty($name)){
var_dump($_FILES);
$location = 'images/'.$name;
if(move_uploaded_file($temp_name, $location)){
echo 'File uploaded successfully';
}
}
} else {
echo 'You should select a file to upload !!';
}
if(isset($name1)){
if(!empty($name1)){
var_dump($_FILES);
$location = 'images/'.$name1;
if(move_uploaded_file($temp_name1, $location)){
echo 'File uploaded successfully';
}
}
} else {
echo 'You should select a file to upload !!';
}
}
?>

Multi image upload

I'm learning PHP and can not find a way to make this work. Did I write correct code to upload multiple images?
I can not think of a reason why this should be wrong.
$imageName = mysql_real_escape_string($_FILES["image, drie1, drie2, drie3, add, strip"]["name"]);
$imageData = mysql_real_escape_string(file_get_contents($_FILES["image"]["tmp_name"]));
$imageType = mysql_real_escape_string($_FILES["image, drie1, drie2, drie3, add, strip"]["type"]);
HTML
<form action="file-upload.php" method="post" enctype="multipart/form-data">
Send these files:<br />
<input name="userfile[]" type="file" /><br />
<input name="userfile[]" type="file" /><br />
<input type="submit" value="Send files" />
</form>
PHP (file-upload.php)
var_dump($_FILES);
This will display the info of the uploaded files
You can add accept attribute to the input to limit the allowed filetypes by extention
Html
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="image_file[]" multiple=""> /* multiple tag is used to upload multiple files */
<input type="submit" name="Submit" value="Submit" />
</form>
Php
<?php
foreach($_FILES["image_file"]["name"] as $key => $value)
{
$name = $value;
$tmp_name = $_FILES["image_file"]["tmp_name"][$key];
$type = $_FILES["image_file"]["type"][$key];
echo $name." , ".$tmp_name." , ".$type."\n";
}
?>

Cannot display content of $_FILES

Have a look at the following code:
<?php
if (isset($_POST['email']))
{
$expertmail=trim($_POST['email']);
echo $expertmail;
$expertfile=$_FILES['upfile']['tmp_name'];
echo $expertfile;
}
?>
<form action="test.php" method="post" name="users" id="users" >
<input name="upfile" id="upfile" type="file" />
<input name="email" id="email" type="text" />
<input type="submit" name="submit_button" id="submit_button" value="ΑΠΟΣΤΟΛΗ" />
</form>
Why 'echo $expertfile' does not display anything?
Thank you
POST Method Uploads gives all the information you need to handle file uploads in PHP. For your case you need: enctype="multipart/form-data":
<form action="test.php" method="post" name="users" id="users" enctype="multipart/form-data">
As Salman A points out, you will also need to check to see if a file was uploaded.

Wordpress - file upload form in page - empty $_FILES array

I'm trying to create a simple fileupload form in my custom Wordpress template:
<form action="<?php echo $current_url = home_url(add_query_arg(array(),$wp->request)); ?>" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">
</form>
On submit, the $_FILES array is empty.
I think the problem is in the action, as the url that is generated is the nice URL, instead of http://domain.com/somepost.php
What should I put into the action, so I get the $_FILES?
Try this
<?php
if(isset($_POST['submit'])){
if($_FILES["file"]["error"] > 0){
echo $_FILES["file"]["error"];
}
else{
echo $_FILES['file']["name"]; // your file name
}
}
?>
<form method="post" action="#" enctype="multipart/form-data">
<input type="file" name="file" />
<input type="submit" name="submit"/>
</form>

Multiple actions on uploaded file

In my website, user have to upload a file, and should have two buttons that redirects to either "action1.php" or "action2.php" based on the submit button user clicked.
<form action="action1.php" method="post" enctype="multipart/form-data" />
<b>Upload a file:<br/>
<input type="hidden" name="MAX_FILE_SIZE" value="31457"/>
<input type="file" name="userfile" id="userfile" size="30" />
<input type="submit" value="GET SEQUENCE" />
</form>
<form action="action2.php" method="post" enctype="multipart/form-data" />
<input type="hidden" name="MAX_FILE_SIZE" value="3145728"/>
<input type="file" name="userfile" id="userfile" size="30" />
<input type="submit" value="GET HELIX INFO" />
Here I have two browse buttons and two actions but the uploaded file is same in both cases. So I want only one browse button and based on what user clicks, it should give either "action1.php" result or "action2.php" result.
<script>
function setAction(form,val,action)
{
form.MAX_FILE_SIZE.value=val;
form.setAttribute('action',action)
form.submit();
}
</script>
<form action="action1.php" method="post" enctype="multipart/form-data" />
<b>Upload a file:<br/>
<input type="hidden" name="MAX_FILE_SIZE" value="31457"/>
<input type="file" name="userfile" id="userfile" size="30" />
<input type="button" value="GET SEQUENCE" onclick="setAction(this.form,31457,'action1.php')"/>
<input type="button" value="GET HELIX INFO" onclick="setAction(this.form,3145728,'action2.php')"/>
</form>
Make a radiobutton named radio and an actions.php file.
Now do this in the actions.php:
<?php
if(isset($_GET["radio"])){
switch($_GET["radio"]){
case "a":
include("action1.php");
break;
case "b":
include("action2.php");
break;
default:
echo "Not valid radio button value";
}
}
else echo "Not valid radio button value";
?>

Categories