I am struggling to get an image upload procedure to work.
I have copied the code form a previously successful site of mine.
The problem is centred around the ['name'] part of
Code: Select all
$_FILES['file']['name']Code: Select all
<?php
session_start();
$pubid = $HTTP_GET_VARS['pubid'];
$imagetype = $HTTP_GET_VARS['ImageType'];
?>
<body bgcolor="#CCCCCC">
<table border="0" width="80%" cellspacing="5" cellpadding="5">
<form action="fileupload.php" method="post" enctype="multipart/fomr-data" target="_self">
<tr>
<td><font color="#000000" size="3" face="Arial, Helvetica, sans-serif"><strong>Comment</strong></font></td>
</tr>
<tr>
<td><textarea name="comment" cols="50" id="comment"></textarea></td>
</tr>
<tr>
<td>
<input type = "file" size="40" name="file">
</td></tr>
<tr>
<td colspan="2"><input type="hidden" name="pubid" value="<?php echo $pubid ?>">
<input name="upload" type="submit" value="upload">
<input type="hidden" name="imagetype" value="<?php echo $imagetype ?>">
<input type="hidden" name="MAX_FILE_SIZE" value="10000"></td>
<td colspan="2"> </td>
<td colspan="2"> </td>
</tr>
<tr><td>
<td colspan="2"> </td>
</tr>
</form>
</table>Code: Select all
<input type = "file" size="40" name="file">Code: Select all
<?php
session_start();
include ('db_fns.php');
echo $HTTP_SESSION_VARS['PubID'];
echo $HTTP_SESSION_VARS['UserID'];
echo $HTTP_SESSION_VARS['RealName'];
$person = $HTTP_SESSION_VARS['RealName'];
$pubid = $_POST['pubid'];
$key_id = $pubid;
$imagetype = $_POST['imagetype'];
$comment = $_POST['comment'];
if (isset($_POST['upload'])){
echo "Upload Set";
//if (!empty($_FILES['file']['name'])){
$formats = array('png','jpg');
echo "Files Set";
$img_path = "/domains/r/runthelakes.co.uk/user/htdocs/ale/images/".$ImageType."/";
echo $img_path;
echo '<br>';
echo $_FILES['file']['name'];
if(!in_array(strtolower(substr($_FILES['file']['name'],-3)),$formats)){
echo "<font face =\"verdona,arial,helvetica\" size=\"2\" color=\"#000000\"><b>Sorry ! only .JPG's and .PNG's are allowed</b></font>";
}else{
$conn=db_connect();
}
$query = sql_return("insert into images (key_id,owner,comment,image_name,image_path,album_id)values('".$key_id."','".$person."','".$comment."','".$_FILES['file']['name']."','".$img_path."','".$imagetype."'");
echo "Query :".$query;
//$result = mysql_query($query) or die (mysql_error());
$newname=mysql_insert_id().".jpg";
copy($_FILES['file']['tmp_name'],$img_path . $newname);
unlink($_FILES['file']['name']);
echo "Image Uploaded Successfully";
//require("THUMBNAIL3.inc");
//thumbs($newname,$img_path,$img_path,"50","th");
//thumbs($newname,$img_path,$img_path,"400","th");
}
else
{
echo "You must specify a file to upload";
exit();
}
//}
?>Code: Select all
//if (!empty($_FILES['file']['name'])){When the line is commented out the code runs but the $_FILES part is missing from the sql insert code that I print to the screen
I also get the incorrect format message that comes from
Code: Select all
if(!in_array(strtolower(substr($_FILES['file']['name'],-3)),$formats)){
echo "<font face =\"verdona,arial,helvetica\" size=\"2\" color=\"#000000\"><b>Sorry ! only .JPG's and .PNG's are allowed</b></font>";Code: Select all
if(!in_array(strtolower(substr($_FILES['file']['name'],-3)),$formats)){Hope someone can help is driving me mad
Cheers
Jamie