Jump to content

please someone help me im about to go insane.... php is doing my head in


Recommended Posts

first i have a standard html page. Just a form that submits data to upload.php

 

http://pixel.imgboard.co.uk

 

here is upload.php - note i know i have some weird echo's but ive been trying for 2 hours to get upload.php to display something... but nothing happens.. i cant even get it to output html. It just goes to upload.php and has a blank page. When i view source there is nothing there. Its literally a blank page. I can't work it out.  someone please help. I'm going to crack up.

 

<?php
ini_set("display_errors", "1");
error_reporting(E_ALL);
session_start();
include 'http://www.imgboard.co.uk/includes/functions.php';



$start =  "
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">  
<html>
<head>
<link rel=\"stylesheet\" type=\"text/css\" href=\"http://www.imgboard.co.uk/style/pixel.css\" />
<title> Pixel - Image Hosting Beta</title>

</head>

<body>
    <div id =\"wrapper\">
    <div class = 'titlebar'>
    <div class = 'titlebarlinkbox'>
    <a href = 'http://www.imgboard.co.uk'>Forum</a>
    <a href = 'http://www.imgboard.co.uk/Wiki.php'>Wikis</a>
    <a href = 'http://www.imgboard.co.uk/bulletins/0'>Bulletins</a>
    <a href = 'http://www.imgboard.co.uk/faq/0'>Faq's</a>
    </div>
    </div>
    <div class = \"logo\"></div>


";


$end =  "
<div class = 'footerLinks'>
     
     Pixel @ 2010 - 2015 ! <br />
    <a href = 'http://www.imgboard.co.uk'>Forum</a> | 
    <a href = 'http://www.imgboard.co.uk/Wiki.php'>Wikis</a> | 
    <a href = 'http://www.imgboard.co.uk/bulletins/0'>Bulletins</a> | 
    <a href = 'http://www.imgboard.co.uk/faq/0'>Faq's</a> | 
    <a href = 'http://www.imgboard.co.uk/pixel/report.php'>Report Image</a>

</div>
<div class = 'TnC'>Pixel is a Trademark of imgboard.co.uk. Please ensure all content uploaded is decent. No Taboo, cp, gore allowed. Porn / memes / misc themes all welcome. Any offensive content will be removed and deleted. Any misuse of the service and result in banning and in seviere cases prosecution.</div>

    </div>
</body>
</html>


";



if(isset($_GET['uploadfile'])){

echo $start;
echo $end;


$validExtensions = array("png", "gif", "jpeg", "jpg", "bmp");
                                       $ext = end(explode(".",$_FILES["image"]["name"]));
                                       $ext2= strtolower($ext);


if ((($_FILES["file"]["type"] == "image/gif")
	|| ($_FILES["file"]["type"] == "image/jpeg")
	|| ($_FILES["file"]["type"] == "image/png")
	|| ($_FILES["file"]["type"] == "image/bmp")
	|| ($_FILES["file"]["type"] == "image/pjpeg"))
	&& ($_FILES["file"]["size"] < 10000000))
	&& in_array($ext2,$validExtensions))
		 {
      

		//create a unique name. 
		$newname = date(dmYhis);
		$newname .= rand(1111,9999);
		//preg replace non alpha numeric characters

		$fname = $_FILES['file']['name'];
		$newname = $newname . "." .$ext2;

		$location = "http://www.imgboard.co.uk/images/".$newname;
      
		//copy the file. 

		if(move_uploaded_file($_FILES['file']['tmp_name'],$location)){

			//file uploaded create display Page. 
			$t = $_POST['tags'];
			add_uploaded_image($location,$t);
			file_upload_display_page($location);

		}

		else{

			die("Error Occured Moving File");
		}





	 }

	 else{

	 die("wrong mime type");

	 }






}



function add_uploaded_image($link, $tags){

$c = protect($_COOKIE['supercookie']);
$ip = $_SERVER['REMOTE_ADDR'];
$t = protect($tags);

mysql_query("INSERT INTO pixel (filename,tags,date,ip,cookie) VALUES ('$link','$t',NOW(),'$ip','$c')") or die(mysql_error());

}



function file_upload_display_page($location){

echo "

   
    <table class = 'uploadTable' cellspacing = '0'>
    
    
    
    
    <tr>
    <td class = \"label\">
    Image Uploaded: </td><td><img src = '$location' HEIGHT = '150'/>
    </td>
    </tr>
    
    <tr>
    <td class = \"label\">
    Direct Link: </td><td><input type = 'text' name = 'file' id = 'file'  value = '$location'/>
    </td>
    </tr>
    <tr>
    <td class = \"label\">
    Html Code </td><td><input type = 'text' name = 'tags'  value = \"<img src = '$location' ALT = 'Hosted On http://Pixel.imgboard.co.uk'/>\"/>
    </td>
    </tr>
    <tr>
    <td>
     <td class = \"label\">
    BB Code: </td><td><input type = 'text' name = 'file' id = 'file'  value = '[img=http://$location]'/>
    </td>
    </td>
    </tr>
      
    
    </table>
    
    
    


";






}









 

If nothing is displayed it usually means PHP has come across an error. When developing you should set error_reporting to E_ALL and turn display_errors on. That way you will be notified immediately  and you wont be looking at a blank screen and asking yourself WTF!

 

Add these two lines after your opening PHP tag at the top of your page

error_reporting(E_ALL);
ini_set('displayer_errors', 1);

 

EDIT: OH, I noticed you have already done this.

 

Any way. You cant include a file using a url

include 'http://www.imgboard.co.uk/includes/functions.php';

 

This will just include the output of this including file. You should use local file paths with includes eg

include 'includes/functions.php';

 

 

Also, you really, really, really need to separate your HTML from your PHP.  Don't echo an entire HTML document.  Stuff those strings into files you can include.  It will make debugging much easier as you won't have to dig through miles of non-PHP code, let alone having to worry if the long strings are quoted properly.

ok i changed the upload.php to this - still no output... but getting an error log file.

 

PHP Parse error:  syntax error, unexpected T_BOOLEAN_AND in /home/imgboard/public_html/pixel/upload.php on line 27

(This is the in_array line when comparing the mime type.s)

 

<?php
ini_set("display_errors", "1");
error_reporting(E_ALL);
session_start();
include '../includes/functions.php';
include 'top.html';



if(isset($_GET['uploadfile'])){

echo $start;
echo $end;


$validExtensions = array("png", "gif", "jpeg", "jpg", "bmp");
                                       $ext = end(explode(".",$_FILES["image"]["name"]));
                                       $ext2= strtolower($ext);


if ((($_FILES["file"]["type"] == "image/gif")
	|| ($_FILES["file"]["type"] == "image/jpeg")
	|| ($_FILES["file"]["type"] == "image/png")
	|| ($_FILES["file"]["type"] == "image/bmp")
	|| ($_FILES["file"]["type"] == "image/pjpeg"))
	&& ($_FILES["file"]["size"] < 10000000))
	&& in_array($ext2,$validExtensions))
		 {
      

		//create a unique name. 
		$newname = date(dmYhis);
		$newname .= rand(1111,9999);
		//preg replace non alpha numeric characters

		$fname = $_FILES['file']['name'];
		$newname = $newname . "." .$ext2;

		$location = "http://www.imgboard.co.uk/images/".$newname;
      
		//copy the file. 

		if(move_uploaded_file($_FILES['file']['tmp_name'],$location)){

			//file uploaded create display Page. 
			$t = $_POST['tags'];
			add_uploaded_image($location,$t);
			file_upload_display_page($location);

		}

		else{

			die("Error Occured Moving File");
		}





	 }

	 else{

	 die("wrong mime type");

	 }






}



function add_uploaded_image($link, $tags){

$c = protect($_COOKIE['supercookie']);
$ip = $_SERVER['REMOTE_ADDR'];
$t = protect($tags);

mysql_query("INSERT INTO pixel (filename,tags,date,ip,cookie) VALUES ('$link','$t',NOW(),'$ip','$c')") or die(mysql_error());

}



function file_upload_display_page($location){

echo "

   
    <table class = 'uploadTable' cellspacing = '0'>
    
    
    
    
    <tr>
    <td class = \"label\">
    Image Uploaded: </td><td><img src = '$location' HEIGHT = '150'/>
    </td>
    </tr>
    
    <tr>
    <td class = \"label\">
    Direct Link: </td><td><input type = 'text' name = 'file' id = 'file'  value = '$location'/>
    </td>
    </tr>
    <tr>
    <td class = \"label\">
    Html Code </td><td><input type = 'text' name = 'tags'  value = \"<img src = '$location' ALT = 'Hosted On http://Pixel.imgboard.co.uk'/>\"/>
    </td>
    </tr>
    <tr>
    <td>
     <td class = \"label\">
    BB Code: </td><td><input type = 'text' name = 'file' id = 'file'  value = '[img=http://$location]'/>
    </td>
    </td>
    </tr>
      
    
    </table>
    
    
    


";



include 'bottom.html';


}














?>

There was a few problems...  Here is your code cleaned up a bit...

 

It ran, but I still dont understand how your using $_GET to POST a file from a form...

 

This has a great explanation on uploading files.

 

http://www.php.net/manual/en/features.file-upload.post-method.php

 

<?php
ini_set("display_errors", "1");
error_reporting(E_ALL);
session_start();
include '../includes/functions.php';
include 'top.html';


/*I think you might want to change this to 
if(isset($_POST['uploadfile'])){
*/

if(isset($_GET['uploadfile'])){

echo $start;
echo $end;


$validExtensions = array("png", "gif", "jpeg", "jpg", "bmp");
                                       $ext = end(explode(".",$_FILES["image"]["name"]));
                                       $ext2= strtolower($ext);


if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/png") || ($_FILES["file"]["type"] == "image/bmp") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 10000000)
	&& in_array($ext2,$validExtensions))
		 {
      

		//create a unique name. 
		$newname = date(dmYhis);
		$newname .= rand(1111,9999);
		//preg replace non alpha numeric characters

		$fname = $_FILES['file']['name'];
		$newname = $newname . "." .$ext2;

		$location = "http://www.imgboard.co.uk/images/".$newname;
      
		//copy the file. 

		if(move_uploaded_file($_FILES['file']['tmp_name'],$location)){

			//file uploaded create display Page. 
			$t = $_POST['tags'];
			add_uploaded_image($location,$t);
			file_upload_display_page($location);

		}

		else{

			die("Error Occured Moving File");
		}





	 }

	 else{

	 die("wrong mime type");

	 }






}



function add_uploaded_image($link, $tags){

$c = protect($_COOKIE['supercookie']);
$ip = $_SERVER['REMOTE_ADDR'];
$t = protect($tags);

mysql_query("INSERT INTO pixel (filename,tags,date,ip,cookie) VALUES ('$link','$t',NOW(),'$ip','$c')") or die(mysql_error());

}



function file_upload_display_page($location){

echo "

   
    <table class = 'uploadTable' cellspacing = '0'>
    
    
    
    
    <tr>
    <td class = \"label\">
    Image Uploaded: </td><td><img src = '".$location."' HEIGHT = '150'/>
    </td>
    </tr>
    
    <tr>
    <td class = \"label\">
    Direct Link: </td><td><input type = 'text' name = 'file' id = 'file'  value = '".$location."'/>
    </td>
    </tr>
    <tr>
    <td class = \"label\">
    Html Code </td><td><input type = 'text' name = 'tags'  value = \"<img src = '".$location."' ALT = 'Hosted On http://Pixel.imgboard.co.uk'/>\"/>
    </td>
    </tr>
    <tr>
    <td>
     <td class = \"label\">
    BB Code: </td><td><input type = 'text' name = 'file' id = 'file'  value = '[img=http://".$location."]'/>
    </td>
    </td>
    </tr>
      
    
    </table>
    
    
    


";



include 'bottom.html';


}














?>

 

i have cleaned the code up... i am using post to send the file. But the action in the form is set to

 

upload.php?uploadfile=0

 

ok here is the code i have now - The code seems to semi execute now. But i get these errors...i assume there is a problem with the file location

 

Notice: Undefined index: file in /home/imgboard/public_html/pixel/upload.php on line 16

 

Notice: Undefined index: file in /home/imgboard/public_html/pixel/upload.php on line 20

 

Notice: Undefined index: file in /home/imgboard/public_html/pixel/upload.php on line 21

 

Notice: Undefined index: file in /home/imgboard/public_html/pixel/upload.php on line 22

 

Notice: Undefined index: file in /home/imgboard/public_html/pixel/upload.php on line 23

 

Notice: Undefined index: file in /home/imgboard/public_html/pixel/upload.php on line 24

wrong mime type

 


<?php
error_reporting(E_ALL);
ini_set("display_errors", "1");

session_start();
include '../includes/functions.php';
include 'top.html';



if(isset($_GET['uploadfile'])){



$validExtensions = array("png", "gif", "jpeg", "jpg", "bmp");
                                       $ext = end(explode(".",$_FILES["file"]["name"]));
                                       $ext2= strtolower($ext);


if ((($_FILES["file"]["type"] == "image/gif")
	|| ($_FILES["file"]["type"] == "image/jpeg")
	|| ($_FILES["file"]["type"] == "image/png")
	|| ($_FILES["file"]["type"] == "image/bmp")
	|| ($_FILES["file"]["type"] == "image/pjpeg"))
	&& ($_FILES["file"]["size"] < 10000000)
	&& in_array($ext2,$validExtensions))
		 {
      

		//create a unique name. 
		$newname = date(dmYhis);
		$newname .= rand(1111,9999);
		//preg replace non alpha numeric characters

		$fname = $_FILES['file']['name'];
		$newname = $newname . "." .$ext2;

		$location = "http://www.imgboard.co.uk/images/".$newname;
      
		//copy the file. 

		if(move_uploaded_file($_FILES['file']['tmp_name'],$location)){

			//file uploaded create display Page. 
			$t = $_POST['tags'];
			add_uploaded_image($location,$t);
			file_upload_display_page($location);

		}

		else{

			die("Error Occured Moving File");
		}





	 }

	 else{

	 die("wrong mime type");

	 }






}



function add_uploaded_image($link, $tags){

$c = protect($_COOKIE['supercookie']);
$ip = $_SERVER['REMOTE_ADDR'];
$t = protect($tags);

mysql_query("INSERT INTO pixel (filename,tags,date,ip,cookie) VALUES ('$link','$t',NOW(),'$ip','$c')") or die(mysql_error());

}



function file_upload_display_page($location){

echo "

   
    <table class = 'uploadTable' cellspacing = '0'>
    
    
    
    
    <tr>
    <td class = 'label'>
    Image Uploaded: </td><td><img src = '$location' HEIGHT = '150'/>
    </td>
    </tr>
    
    <tr>
    <td class = 'label'>
    Direct Link: </td><td><input type = 'text' name = 'file' id = 'file'  value = '$location'/>
    </td>
    </tr>

    <tr>
    
    <td class = 'label'> BB Code: </td> <td> [img=http://".$location."] </td>
    
    </tr>
      
    
    </table>
    
    
    


";



include 'bottom.html';


}














?>


but its erroring because its not recognising the $_FILES['file'] bit - but in the form i have put <type = 'file' name = 'file'>

 

i thought there might have been a mixup so i switched all instances of file to image but still have the same problem.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.