Hi Guys and Girls,
I'm fairly new to PHP and am having a slight problem. I'm creating an image upload form and storing the image in a folder on the server and the image path in the database, all of this works fine (In my database it shows the correct path to the image and the file is on the server).
The problem lies when i try to display the image on the page, when i view the source of the image, it is correct, so i don't know what is going on, could it be that i'm uploading in the wrong format?
Here's my upload code, it test to see wether they have already uploaded a file as they are only allowed to do it once, it's tested against the default image:
<?php
$pulledProfileCode = $_SESSION['sesProfileCode'];
$conn = mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("taafc_com_au_-_taafc", $conn) or die(mysql_error());
$imageAdded = "select imagePath from profiledetails where profileCode = '$pulledProfileCode'";
$imageAdded_res = mysql_result(mysql_query($imageAdded), 0);
if($imageAdded_res == "images/playerprofileimages/none.gif"){
echo "
<p>Please select your image that you want to appear in your player profile. Please note you only get to select your image once so choose the right one first, also file size is limited to 100Kb</p>
<form enctype=\"multipart/form-data\" action=\"uploader.php\" method=\"POST\">
<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"100000\" />
<p>Image to be added to your profile:</> <input name=\"userfile\" type=\"file\" class=\"forms\"/>
<br><br><input type=\"submit\" value=\"Add Image\" class=\"formButtons\"/>
</form>";
} else {
echo "<h1>Sorry, you have already selected your image</h1>
<p>To have your image and player profile details reset, please contact <a href = \"mailto:websupport@taafc.com.au\">websupport@taafc.com.au</a>
<br>
<a href = \"#\" onClick = \"window.close();\">Close Window</a>";
}
?>
Here is the upload process code:
<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.
$uploaddir = 'images/playerprofileimages/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
$_FILES['imagefile']['type'] == "image/pjpeg";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
$pulledProfileCode = $_SESSION['sesProfileCode'];
$path = $uploadfile;
$conn = mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("taafc_com_au_-_taafc", $conn) or die(mysql_error());
$id = "select id from profiledetails where profileCode = '$pulledProfileCode'";
$id_res = mysql_query($id);
if (mysql_num_rows($id_res) == 1) {
$id = mysql_result($id_res, 0, 'id');
}
$_SESSION['sesImagePath'] = $path;
$addData = "replace into profiledetails values ('$id', ' ', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,NULL, NULL, '0', '$pulledProfileCode', '$path')";
mysql_query($addData) or die(mysql_error());
echo "<h1>File is valid, and was successfully added to your profile.</h1><p><a href = \"#\" onClick = \"window.close();\">Close Window</a></p>";
} else {
die("<h1>Error!</h1><p>There was an error uploading your file, please make sure the file size is under 100Kb<br><a href = \"#\" onClick = \"history.back();\">Backwards</a></p>");
}
?>
And here is the code to display the image on the page:
//display selected image
$get_image = "select imagePath from profiledetails where id = $_POST[sel_id]";
$get_image_res = mysql_query($get_image);
if (mysql_num_rows($get_image_res) == 1) {
$image = mysql_result($get_image_res, 0, 'imagePath');
$display_block .= "<img src=\"$image\"/>";
}
Thanks in advance for any help/suggestions that any of you may have.
Casey