0

This may be something so stupidly simple I'm not seeing it. Doing a file upload & rename, then sending it to a confirmation page. File upload & rename works perfectly. But when the script is finished, I get a blank page and it does not redirect to mypage.php. I suspect the last IF statement. Anyone see what I am missing?

<?php
require "db_conn.php";
$ID=$_POST['ID'];

if ($_FILES['wimage']['error'] > 0)
  {
    echo 'Problem: ';
    switch ($_FILES['wimage']['error'])
    {
      case 1:  echo 'File exceeded upload_max_filesize';  break;
      case 2:  echo 'File exceeded max_file_size';  break;
      case 3:  echo 'File only partially uploaded';  break;
      case 4:  echo 'No file uploaded';  break;
    }
    exit;
  }

  // put the file where we'd like it
  $upfile = $SCIMAGEPATHLISTINGS.'/'.$_POST['ID'].'.jpg';

  if (is_uploaded_file($_FILES['wimage']['tmp_name']))
  {
     if (!move_uploaded_file($_FILES['wimage']['tmp_name'], $upfile))
     {
        echo 'Problem: Could not move file to destination directory';
        exit;
     }
  }
  else
  {
    echo 'Problem: Possible file upload attack. Filename: ';
    echo $_FILES['wimage']['name'];
    exit;
  }

  if (move_uploaded_file($_FILES['wimage']['tmp_name'], $upfile))
{
 header ("Location: mypage.php?ok=add&Address=$ID");
}
?>
  • What happens if you enable debugging on your server, either through `var_dump`s here and there or `error_reporting`? Have you tried anything to solve this problem on your own? – Nico Haase Apr 06 '18 at 15:47

2 Answers2

0

See the link which says

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

In your case there are output before header() which may generating error and it may possible that your error reporting is off thus giving empty page

Digvijaysinh Gohil
  • 1,367
  • 2
  • 15
  • 30
  • ok, then how do I get the code to go to mypage.php? The header method is the only way I've ever used. – user9587282 Apr 06 '18 at 15:49
  • Firstly comments those `exit`s, they may be the cause your script terminates before executing your last if – Digvijaysinh Gohil Apr 06 '18 at 15:52
  • Commented the exits out. No change in behavior. – user9587282 Apr 06 '18 at 15:56
  • If it is the header issue then this answer will definitely help you https://stackoverflow.com/a/15598695 – Digvijaysinh Gohil Apr 06 '18 at 15:59
  • Here's what I changed to, same non-result. if (move_uploaded_file($_FILES['wimage']['tmp_name'], $upfile)) { echo ""; } – user9587282 Apr 06 '18 at 16:06
  • I have tried various solutions, including the one above and an ob style below, but still a blank page. ob_start(); if (move_uploaded_file($_FILES['wimage']['tmp_name'], $upfile)) { header("Location: URLPATH/myfile.php?Address=$ID"); ob_end_flush(); exit; } No errors generated and no relocation. – user9587282 Apr 06 '18 at 16:59
-1

Found a solution. Got rid of the original else statement and replaced it with my header code. Now it works like I needed it to with no errors. Thank you all for you assistance!

  if (is_uploaded_file($_FILES['wimage']['tmp_name']))
{
     if (!move_uploaded_file($_FILES['wimage']['tmp_name'], $upfile))
     {
        echo 'Problem: Could not move file to destination directory';
     //   exit;
  }
  else 
  {
 echo header ("Location: mypage.php?ok=add&Address=$ID");
  }
}