# HTTP 400 Bad Request / webpage cannot be found

**URL:** <https://forum.kirupa.com/t/http-400-bad-request-webpage-cannot-be-found/327354>\
**Category:** flash\
**Created:** [February 23, 2012, 4:51pm UTC](https://forum.kirupa.com/t/http-400-bad-request-webpage-cannot-be-found/327354 "2012-02-23T16:51:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Scotty13](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@Scotty13](https://forum.kirupa.com/u/Scotty13)\
**Post date:** [February 23, 2012, 4:51pm UTC](https://forum.kirupa.com/t/http-400-bad-request-webpage-cannot-be-found/327354/1 "2012-02-23T16:51:12Z")

</div>

Building a photo album / upload image page in my website.

I have a page that’s giving me trouble… action.php

Error when I test in browser: HTTP 400 Bad Request / webpage cannot be found (highlighted below)

\<?php  
define(‘PHPWG\_ROOT\_PATH’,’./’);  
include\_once(PHPWG\_ROOT\_PATH.‘include/common.inc.php’);  
// Check Access and exit when user status is not ok  
check\_status(ACCESS\_GUEST);  
function guess\_mime\_type($ext)  
{  
switch ( strtolower($ext) )  
{  
case “jpe”: case “jpeg”:  
case “jpg”: $ctype=“image/jpeg”; break;  
case “png”: $ctype=“image/png”; break;  
case “gif”: $ctype=“image/gif”; break;  
case “tiff”:  
case “tif”: $ctype=“image/tiff”; break;  
case “txt”: $ctype=“text/plain”; break;  
case “html”:  
case “htm”: $ctype=“text/html”; break;  
case “xml”: $ctype=“text/xml”; break;  
case “pdf”: $ctype=“application/pdf”; break;  
case “zip”: $ctype=“application/zip”; break;  
case “ogg”: $ctype=“application/ogg”; break;  
default: $ctype=“application/octet-stream”;  
}  
return $ctype;  
}  
function do\_error( $code, $str )  
{  
set\_status\_header( $code );  
echo $str ;  
exit();  
}  
　  
if (!isset($\_GET[‘id’])  
or !is\_numeric($\_GET[‘id’])  
or !isset($\_GET[‘part’])  
or !in\_array($\_GET[‘part’], array(‘t’,‘e’,‘i’,‘h’) ) )  
{  
\*\*do\_error(400, ‘Invalid request - id/part’);  
\*_}  
$query = ’  
SELECT \* FROM ‘. IMAGES\_TABLE.’  
WHERE id=’.$\_GET[‘id’].’  
;’;  
$result = pwg\_query($query);  
$element\_info = pwg\_db\_fetch\_assoc($result);  
if ( empty($element\_info) )  
{  
do\_error(404, ‘Requested id not found’);  
}  
// $filter[‘visible\_categories’] and $filter[‘visible\_images’]  
// are not used because it’s not necessary (filter \<\> restriction)  
$query=’  
SELECT id  
FROM ‘.CATEGORIES\_TABLE.’  
INNER JOIN ‘.IMAGE\_CATEGORY\_TABLE.’ ON category\_id = id  
WHERE image\_id = ‘.$\_GET[‘id’].’  
‘.get\_sql\_condition\_FandF(  
array(  
‘forbidden\_categories’ =\> ‘category\_id’,  
‘forbidden\_images’ =\> ‘image\_id’,  
),  
’ AND’  
).’  
LIMIT 1  
;’;  
if ( pwg\_db\_num\_rows(pwg\_query($query))\<1 )  
{  
do\_error(401, ‘Access denied’);  
}  
include\_once(PHPWG\_ROOT\_PATH.‘include/functions\_picture.inc.php’);  
$file=’’;  
switch ($\_GET[‘part’])  
{  
case ‘t’:  
$file = get\_thumbnail\_path($element\_info);  
break;  
case ‘e’:  
$file = get\_element\_path($element\_info);  
break;  
case ‘i’:  
$file = get\_image\_path($element\_info);  
break;  
case ‘h’:  
if ( $user[‘enabled\_high’]!=‘true’ )  
{  
do\_error(401, ‘Access denied h’);  
}  
$file = get\_high\_path($element\_info);  
break;  
}  
if ( empty($file) )  
{  
do\_error(404, ‘Requested file not found’);  
}  
if ($\_GET[‘part’] == ‘h’) {  
pwg\_log($\_GET[‘id’], ‘high’);  
}  
else if ($\_GET[‘part’] == ‘e’)  
{  
pwg\_log($\_GET[‘id’], ‘other’);  
}  
$http\_headers = array();  
$ctype = null;  
if (!url\_is\_remote($file))  
{  
if ( !@is\_readable($file) )  
{  
do\_error(404, “Requested file not found - $file”);  
}  
$http\_headers[] = ‘Content-Length: ‘.@filesize($file);  
if ( function\_exists(‘mime\_content\_type’) )  
{  
$ctype = mime\_content\_type($file);  
}  
$gmt\_mtime = gmdate(‘D, d M Y H:i:s’, filemtime($file)).’ GMT’;  
$http\_headers[] = 'Last-Modified: '.$gmt\_mtime;  
// following lines would indicate how the client should handle the cache  
/_ $max\_age=300;  
$http\_headers[] = ‘Expires: ‘.gmdate(‘D, d M Y H:i:s’, time()+$max\_age).’ GMT’;  
// HTTP/1.1 only  
$http\_headers[] = ‘Cache-Control: private, must-revalidate, max-age=’.$max\_age;\*/  
if ( isset( $\_SERVER[‘HTTP\_IF\_MODIFIED\_SINCE’] ) )  
{  
set\_status\_header(304);  
foreach ($http\_headers as $header)  
{  
header( $header );  
}  
exit();  
}  
}  
if (!isset($ctype))  
{ // give it a guess  
$ctype = guess\_mime\_type( get\_extension($file) );  
}  
$http\_headers[] = ‘Content-Type: ‘.$ctype;  
if (!isset($\_GET[‘view’]))  
{  
$http\_headers[] = ‘Content-Disposition: attachment; filename="’.$element\_info[‘file’].’";’;  
$http\_headers[] = ‘Content-Transfer-Encoding: binary’;  
}  
else  
{  
$http\_headers[] = ‘Content-Disposition: inline; filename="’  
.basename($file).’";’;  
}  
foreach ($http\_headers as $header)  
{  
header( $header );  
}  
// Looking at the safe\_mode configuration for execution time  
if (ini\_get(‘safe\_mode’) == 0)  
{  
@set\_time\_limit(0);  
}  
@readfile($file);  
?\>
