Hi.
I am trying to create an image upload form with html and php. The form is ok and shows. But when I add my php code, I get a blank page when I visit the page in my browser. Can somebody please check my code and point out what is wrong with my php code? Help appreciated.
Thank you.
Here is my code :
[CODE]<html>
<head>
<title>dfd</title>
</head>
<body>
<form method=”post” action=”test.php” enctype=”multipart/form-data”>
<input type=”hidden” name=”maxFileSize” value=”300000″ />
<input type=”text” name=”name” id=”name”/><br /><br />
<input type=”text” name=”score” id=”score”/><br /><br />
<input type=”file” name=”screenshot” id=”screenshot”/><br /><br />
<input type=”submit” name=”submit” id=”submit” />
</form>
<?php
if(isset($_POST[‘submit’])){
$name=$_POST[‘name’];
$score=$_POST[‘score’];
$screenshot=$_FILES[‘screenshot’][‘name’];
$screenshot_size=$_FILES[‘screenshot’][‘size’];
$screenshot_type=$_FILES[‘screenshot’][‘type’];
if(!empty($name) && !empty($score) && !empty($screenshot)){
require_once(‘appvars.php’);
if((($screenshot_type == ‘image/png’) || ($screenshot_type == ‘image/jpeg’) || ($screenshot_type == ‘image/pjpeg’) || ($screenshot_type == ‘image/gif’)) && ($screenshot_size > 0) && ($screenshot_size <= TEST_MAXFILESIZE)){
if($_FILES[‘screenshot’][‘error’] == 0){
$target = TEST_UPLOADPATH.$screenshot;
if(move_uploaded_file($_FILES[‘screenshot’][‘tmp_name’], $target)){
require_once(‘connectvars.php’);
$query = “INSERT INTO `test` VALUES (0, ‘$name’, ‘$score’, ‘$screenshot’, NOW())”;
$result = mysqli_query($dbConnect, $query);
or die (‘Could not add your highscore. Please try again’);
echo ‘Thank you for adding your score ‘ . $name . ‘<br />’;
echo ‘Your score is ‘ . $score . ‘<br />’;
echo ‘<img src = “‘ . TEST_UPLOADPATH.$screenshot . ‘” alt = “Score image” /><br />’;
$name=””;
$score=””;
$screenshot=””;
mysqli_close($dbConnect);
}
}
else {
echo ‘Error uploading screenshot. High score not added. Please try again’;
}
}
else{
echo ‘High score not added. Your image should be either a PNG, GIF or JPEG and the size should not exceed ‘ . MAX_FILE_SIZE/1024 . ‘kB’;
}
}
else {
echo ‘<p>Please enter all the fields</p>’;
}
}
?>
</body>
</html>