-2

i got this file upload.html where below code resides, and everytime i browse file and submit its failing at isset($_POST). it echoes "didn't upload", its working fine with same file in another folder. all i did was move the whole website folder content to another folder, and it stopped working.

   <h3>File Upload:</h3>
Select a file to upload: <br />
<form method="post" action="" enctype="multipart/form-data">
<input type="file" name="file" size="50" />
<br />
<input type="submit" name="uploadxls" value="Upload File" />
</form>



<?php

include("../include/processxls.php");

date_default_timezone_set('America/Chicago');

if (isset($_POST['uploadxls']) && !empty($_POST['uploadxls']))
{
    echo "test point";
    uploadReport();
}
else 
{
    echo "didn't upload";
}



function uploadReport()
{

$report=basename($_FILES['file']['name']);
$report=str_replace(' ','|',$report);

$tmppath="uploads/".$report;

    if(move_uploaded_file($_FILES['file']['tmp_name'],$tmppath))
    {
        echo " File upload success. Please wait while report is processed....... "; 

        processxls($tmppath);
    }
    else
    {
        echo "fail";
    }   
}

?>
Vishal Desai
  • 191
  • 3
  • 15
  • Have you tried this in different browsers? Which browser are you using? – PavKR Jun 26 '15 at 00:30
  • yes i tried safari, chrome and firefox – Vishal Desai Jun 26 '15 at 00:42
  • Try `print_r($_REQUEST)` and see if that gives you anything. Post your results here so we can see. – PavKR Jun 26 '15 at 00:45
  • What does `var_dump($_POST)` show? – Barmar Jun 26 '15 at 00:46
  • Array ( [_ga] => GA1.2.1674518736.1434244186 [ci_session] => a:4:{s:10:"session_id";s:32:"0e81f3cc1be3505255b8ef331ca058e0";s:10:"ip_address";s:13:"104.63.10.155";s:10:"user_agent";s:116:"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/600.6.3 (KHTML, like Gecko) Version/8.0.6 Safari/600.6.3";s:13:"last_activity";i:1432694042;}a8b04db2b5f55b49b7896fb1275d9832b81c7f41 ) array(0) { } didn't upload – Vishal Desai Jun 26 '15 at 00:49
  • array(0) is for var_dump($_POST) – Vishal Desai Jun 26 '15 at 00:50
  • Do you have any other scripts running that could redirect a $_POST request? eg. something like a rewrite script? (any includes at the top maybe?) – PavKR Jun 26 '15 at 00:58
  • using admin panel bootstrap, and using angularjs controller to load this upload page. – Vishal Desai Jun 26 '15 at 01:02
  • but if i try even without admin panel stuff and just do plain upload.html file and php that I'm including it still fails to POST – Vishal Desai Jun 26 '15 at 01:09
  • Try this: `print_r(file_get_contents("php://input"));` and see what you get. – PavKR Jun 26 '15 at 01:11
  • at what point should i put that? before if statement? – Vishal Desai Jun 26 '15 at 01:19
  • Put it at the top before your `include(...);` – PavKR Jun 26 '15 at 01:21
  • same thing goes to else and echoes didn't upload – Vishal Desai Jun 26 '15 at 01:24
  • Check this out, maybe it will help: http://stackoverflow.com/questions/15485354/angular-http-post-to-php-and-undefined – PavKR Jun 26 '15 at 01:26
  • Stupid question: Did you also move the `../include/processxls.php` such that its location is still appropriately relative to this php file? – kittykittybangbang Jun 26 '15 at 01:30
  • yes i did, and I'm not getting php related errors, POST is just simply not happening for some reason, i made a copy of original version that is functioning to godaddy server, it didn't work and then i changed the upload.html to upload.php it started working. – Vishal Desai Jun 26 '15 at 02:48

2 Answers2

0

Different browsers ignore the value of submit buttons and do not send this data with the POST

Use a hidden input field instead, and then this will be submitted regardless of browser.

<input type='hidden' name="uploadxls" value="Upload File">
skrilled
  • 5,350
  • 2
  • 26
  • 48
0

You should determine if it is a post using $_SERVER['REQUEST_METHOD']

if( $_SERVER['REQUEST_METHOD'] === "POST" ) {
    // Do checks and logic
}

That way you don't need to worry about the browser sending the submit button or using hidden values. PHP has a built in variable for it, may as well use it.

Lin Meyer
  • 712
  • 5
  • 19