Problem uploading .docx through html form - php

I've made a simple form, with the proper enctype for uploading files. When i try to upload a .docx everything works fine in IE 8 and Safari, but in Firefox or IE 7 or 6 i can't even click submit, nothing happens! Could this still be a server issue? It's an apache server.
Everything works fine if i choose to upload a .doc file
<form enctype="multipart/form-data" method="post" action="index.php">
<input name="file" type="file" />
<input type="submit" name="btnSubmit" value="Submit"/>
</form>

I tested your form in my Wamp2.0 with IE7 and Firefox,and it works fine.I don't think it could be the server issue since the form works well in you IE8.Perhaps you should standardize your html code,or check you browsers.

Related

upload image file from mobile device

Simple upload script (to allow staff members to change their profile pic), works fine from a PC, but when I try and upload a photo from an iPhone, the page just halts, like it's trying to load, and nothing happens.
This is my entire test PHP file:
<?php
if (isset($_POST['submitNewImage'])) {
echo 'it works, and the filename is ' . $_FILES['uploadedFile']['name'];
}
?>
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<br /><br /><br />
<form action="test.php" method="post" enctype="multipart/form-data">
<input type="file" accept="image/*" capture name="uploadedFile" /><br /><br /><br />
<input type="submit" name="submitNewImage" value="Upload" />
</form>
</body>
</html>
Again, this works fine from a PC, but when I touch "Upload" from an iPhone, it just hangs. If I remove the name="uploadedFile", the page executes, but of course there is no file there. How can I get this to recognize an image from an iPhone?
Do you, by any chance, do anything with the image after upload that includes GD?
If you do - is there a difference when you try to upload portrait or landscape image? If portrait works fine, but landscape causes hang (or other way around, cannot remember), problem might be in EXIF data that suggests that image is rotated but GD cannot handle this properly.
Solution lies in getting EXIF data (with exif_read_data()), then stripping it with imagemagick (-strip param in call), following rotating image with either GD or image magick, which will leave you with image that can be manipulated without producing error.
It works for me and it's worth a try!
<?php
if(isset($_POST['submit_image'])) {
$new_image = $_FILES['new_image']['name'];
$new_image_temp = $_FILES['new_image']['tmp_name'];
move_uploaded_file($new_image_temp, "../img/$new_image");
}
?>
<form action="" method="post" enctype="multipart/form-data">
<label for="new_image">Image: </label>
<input type="file" name="new_image">
<input type="submit" name="submit_image" value="Submit">
</form>
Well, it wasn't the code, it's an issue with server the site is on. I have this on a Windows 2008 R2, IIS 7, PHP 5.6. But when I put the same code on a Windows server, 2008 R2, XAMPP, PHP 5.6.15, it works fine. Thank you all for the help, it put me in the right direction. I will post the final result when I figure out the cause, I suspect it's with IIS 7.

Html form having more than one file input not submitting

Html code
<form action="projectOperations.php" enctype="multipart/form-data" method="post">
Upload 1 <input type="file" name="file1"><br>
Upload 2 <input type="file" name="file2"> <br>
Upload 3 <input type="file" name="file3"> <br>
Upload 4 <input type="file" name="file4"> <br>
<input type="submit" value="Submit">
</form>
Php code for projectOperations.php
`var_dump($_POST);`
When i look into console that status still pending
I am using Amazon EC2 instance for this code.
Found two links on stack overflow relevant to this, but no solution found
uploading files stuck on pending
Form having more than one file input not submitted
Can anyone help to understand the problem?
If it server problem what setting i have to change ?
After doing lots of debugging problem was identified as...
It was firewall of network, which was not allowing to upload multiple files.
When I tried to upload files from different network, it worked.
So it was not server or code problem.
Network administrator of the network can fix this error.

Using reCAPTCHA and enctype="multipart/form-data" together

I have a file upload form on which I also want to use the Google reCAPTCHA.
If I have the following
<form method="post">
<input type="file" name="filename">
<div class="g-recaptcha" data-sitekey="***"></div>
<input id="submit" name="submit" type="submit" value="Submit">
</form>
the I can use the reCAPTCHA, but cannot upload the file.
However, if I use:
<form method="post" enctype="multipart/form-data">
<input type="file" name="filename">
<div class="g-recaptcha" data-sitekey="***"></div>
<input id="submit" name="submit" type="submit" value="Submit">
</form>
I can upload the file successfully, and use the reCAPTCHA provided that the file is a text file. I cannot get it to work if I try to upload a pdf file.
When uploading a text file, the $_POST contains the 'g-recaptcha-response', but when uploading a pdf, the $_POST does not contain the 'g-recaptcha-response'.
Can someone explain what is going wrong here?
EDIT
It seems like it's actually a filesize problem.
Files larger than ~200kb cannot be sent whatever their format.
I have upload_max_filesize = 2M in my php.ini file, so I'm not sure why 200kb is too large...
Any thoughts?
EDIT 2: More information
It looks like the $_FILE contains the error code 3: UPLOAD_ERR_PARTIAL.
I don't see why the file cannot be uploaded completely.
EDIT 3: Getting somewhere
I can now upload files. It seems like I need to put the reCAPTCHA before the file input.
<form method="post" enctype="multipart/form-data">
<div class="g-recaptcha" data-sitekey="***"></div>
<input type="file" name="filename">
<input id="submit" name="submit" type="submit" value="Submit">
</form>
Can anyone elaborate on why this might be the case?
Edit 4: Spoke too soon
Switching the order makes the g-recaptcha-response' appear in $_POST, but I am still getting the error code 3: UPLOAD_ERR_PARTIAL.
Edit 5
It looks like the file is being uploaded correctly, since I can see it in the header parameters (firefox debugger). It seems like php is just not filling in the $_FILE array properly...
I tried the same code on a different server and it worked fine.
Looks like the problem was that the server I set up has some sort of configuration issue. It actually has nothing to do with the interaction of reCAPTCHA and the file input + enctype.
I will update if I figure out what the configuration problem is.

Poco HTML Form POST data coming through empty

I have a desktop application passing POST data (text and an image file) onto a PHP file on an Apache Webserver. For some reason the POST data is coming through empty. Does anyone have any idea what could be causing this?
All I am trying for now is to display the POST data using:
<?php print_r($_POST); ?>
But I'm getting nothing. No errors and no data. The strange thing is this works perfectly on my old server - but with my new host the $_POST var is coming through empty so I'm confident it isn't an issue with the app.
The desktop app was built by someone else using Poco to send the HTML Form data so I don't know too much about it but I know if definitely works as it is currently working on my current other webserver.
Weirder still, when I don't attach an image everything works as expected. As soon as an image is attached (<100kb) I get no data whatsoever.
The Poco HTML Form is using multipart/form-data as the encoding type when an file is attached and application/x-www-form-urlencoded when there is no attachment (default).
I'm stumped here and wondering if anyone knows what could be going on or at least what I should be looking to try at?
Thanks in advance.
Edit: I also forgot to mention that it works if I submit it from another webpage without issue.
Double edit: Here is the equivalent of the form in HTML:
<form enctype="multipart/form-data" action="http://DOMAIN.COM/savedata.php" method="POST">
name: <input type="text" name="name" /><br />
email: <input type="text" name="email" /><br />
gender: <select name="gender"><option value="0">Female</option><option value="1">Male</option></select><br />
photo: <input name="photo" type="file" /><br />
<input type="submit" value="Upload File" /></form>

Multiple file input image upload IE 8

Good Day, I have a form with multiple file input fields. I have a script that automatically adds another file input field on change. This is for a image upload functionality ( so that the user can upload multiple images in one go ). In Firefox, it works fine, but it fails on ie8.
this how the form looks like when many images were selected
form.html
<form class="ysForm" action="uploadImage.php" encType="multipart/form-data" method="post">
<input name="ys-file_0" class="ysFile" type="file" multi_selector="[object Object]"/>
<input name="ys-file_1" class="ysFile" type="file" multi_selector="[object Object]"/>
<input name="ys-file_2" class="ysFile" type="file" multi_selector="[object Object]"/>
</form>
uploadImage.php
foreach( $_FILES as $theFile ) {
//do image resize and save to a directory code
}
But uploadImage does not seem to get the image files.
Please help
According to other answers, such as the one here, IE8 doesn't support the multiple option for file inputs.
IE8 doesn't support multiple file uploading with
You can see this info:
IE8 - input (type="file") get files
http://social.msdn.microsoft.com/Forums/en-US/f0e72657-962f-4254-b95c-c47482401899/multiple-file-uploading-in-ie9-and-older-versions?forum=ieextensiondevelopment
Most modern browsers (including IE8) support multiple file uploading with a single dialog. The syntax is
<input type="file" multiple="true" name="upload" />
Your form will call your php script multiple times, once for each image.
That being said, I suggest using Uploadify, http://www.uploadify.com/, as it's a lot easier. There are also some fancy JQuery based solutions.

Categories