0
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL|E_STRICT);
include_once("alphaID.php");
include_once("displayimage.php");
//include_once("insertdata.php");
//generate unique id
$key = microtime() + floor(rand()*10000);
$newname = alphaID($key);
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.
$ext = explode('.',$_FILES['userfile']['name']);
$extension = '.'.$ext[1];
$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
$filepath = '/var/www/html/testing/'.$newname.$extension;
move_uploaded_file($_FILES['userfile']['tmp_name'], $filepath));
header('Location: displayimage.php?img='.$newname.);
exit;
?>

I can't seem to get the header function at the bottom to work. I cannot see any output in the code and have tried many things in an attempt to get it to work.

Sam
  • 7,252
  • 16
  • 46
  • 65
Emmett
  • 357
  • 2
  • 4
  • 15
  • What is in displayimage.php? Is it your HTML for your page? – KevBot Apr 02 '14 at 07:33
  • @KevBot Basically just an isset($_GET['img'])) {}; and then a print output that uses the alphaID.php script. – Emmett Apr 02 '14 at 07:35
  • is `$newname` getting set properly? – anurupr Apr 02 '14 at 07:38
  • @anurpr $newname is defined in the code above, what do you mean? – Emmett Apr 02 '14 at 07:39
  • make sure that the files that you are including inside the page is not doing any output , i mean the two pages (alphaID.php,displayimage.php) – Leo Bali Apr 02 '14 at 07:41
  • @LeoBali none of them have any output, plus what's the point of using the header function if the page that you are re-directing to cannot have any output what so ever? – Emmett Apr 02 '14 at 07:44
  • @Emmett i mean make sure that there is nothing that makes an output before using the header function – Leo Bali Apr 02 '14 at 07:47
  • It's not a matter of outputting data. You can output data on `displayimage.php`. When you use the `Location` function, you are sending the user to another location. It's not like PHP `include` or `require` where you can output whatever you want in those. – KevBot Apr 02 '14 at 07:47
  • I found some errors in your code. See the edits below. – KevBot Apr 02 '14 at 07:57

2 Answers2

1

You cannot have any output before you send headers. Since you are outputting in displayimage.php, your location function will fail.

Here is some great reading on StackOverflow about this issue:

How to fix "Headers already sent" error in PHP

EDIT

You have a syntax error in your header call. You have an extra period. Remove the period after $newname. You should have:

header('Location: displayimage.php?img='.$newname);

Also, you have too many ( on your move_uploaded_file function. This is causing a syntax error as well. You should have:

move_uploaded_file($_FILES['userfile']['tmp_name'], $filepath);

Any time you do not see any output whatsoever, you usually have a syntax error. Just one syntax error will stop the entire page from executing.

Community
  • 1
  • 1
KevBot
  • 17,900
  • 5
  • 50
  • 68
  • Even if I remove the output inside of displayimage.php I still have the same problem, plus the header() function is inside index.php as shown above ^ not displayimage.php so I cannot see what the issue would be with having output inside displayimage.php – Emmett Apr 02 '14 at 07:41
  • Ok, that's interesting. Just as a side note however, that the code that would be printing is executed first because it is above your "Location" function. I'll continue to troubleshoot – KevBot Apr 02 '14 at 07:44
  • yep that fixed it completely, thank you so much. I can't believe it was something as simple as removing a period and a extra bracket. Thanks heaps man. – Emmett Apr 02 '14 at 08:00
-1
header('Location: displayimage.php?img='.$newname**.**); 

the pb is the additionnal dot

InnocentKiller
  • 5,234
  • 7
  • 36
  • 84