0

Here's the form processing code:

$name = $_POST['name'];
$score = $_POST['score'];
$screenshot = time();
$screenshot .= $_FILES['screenshot']['name']; // the name of the file to save
$target = GW_UPLOADPATH . $screenshot;
$screenshot_size = $_FILES['screenshot']['size'];
$screenshot_type = $_FILES['screenshot']['type'];

And here is the form in HTML (also including jQuery):

<div data-role="page" id="main">
  <div data-role="header" style="text-align: left;font-size: 20px;">
        <?php if($mobile) echo $title; ?>
  </div><!-- /header -->
  <div data-role="content">
  <form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <div data-role="fieldcontainer" class="score">
    <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo GW_MAXUPLOADSIZE; ?>" />
    <label for="name">Name:</label>
    <input type="text" id="name" name="name" value="<?php if (!empty($name)) echo $name; ?>" /><br />
    <label for="score">Score:</label>
    <input type="number" id="score" name="score" value="<?php if (!empty($score)) echo $score; ?>" /><br />
    <label for="screenshot">Screen shot:</label>
    <input type="file" id="screenshot" name="screenshot" />
    <input type="submit" value="Add" name="submit" />
    </div><!-- /fieldcontainer -->
  </form>

The upload processes fine if I submit on a desktop computer, but when I access the site on my Android Chrome browser, it fails. Using error reporting:

Notice: Undefined index: screenshot in C:\Apache2.2\htdocs\gw\modtest.php on line 45 Notice: Undefined index: screenshot in C:\Apache2.2\htdocs\gw\modtest.php on line 47 Notice: Undefined index: screenshot in C:\Apache2.2\htdocs\gw\modtest.php on line 48 Notice: Undefined index: screenshot in C:\Apache2.2\htdocs\gw\modtest.php on line 52

I searched for a similar question and found one but the only answer was an unhelpful "php is server side, not client side." Any help or explanation would be very helpful. Thanks!

3
  • You may need to add $screenshot .= $_FILES['screenshot']['tmp_name']; Jul 23, 2014 at 20:50
  • jQuery mobile sometimes modifies your original HTML. I'd take a look at the rendered source on a mobile device (couldn't tell you how to do it on an Android).
    – Patrick Q
    Jul 23, 2014 at 20:53
  • Okay I read about the solution in the book jQuery Mobile Up and Running. It had to be a non-ajax form, since jQuery automatically forces forms to ajax. For future reference to anyone reading, the code is: <form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" data-ajax="false"> Thanks you guys for the hint, particularly the part about jQuery modifying the code which was somewhat right. It works correctly now :)
    – nixhex
    Jul 24, 2014 at 7:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.