This has really got me stumped as it just doesn't work.
What confused me even more is that this is a copy of another file and I've simply amended the names.
Code:
<?php
session_start();
if (!isset($_SESSION['uid'])) {
die ("You need to be logged in to view this page.<br /><a href='index.php'>Login</a>");
}
include_once ('/home/includes/dbc.php');
if ($_POST['Submit'] == 'Save') {
$newdetails = $_POST['lowercontent'];
$newimageALT = $_POST['lowercontentalt'];
//Retrieving Variables
@$upload_Name = $_FILES['upload']['name'];
@$upload_Size = $_FILES['upload']['size'];
@$upload_Temp = $_FILES['upload']['tmp_name'];
@$upload_Mime_Type = $_FILES['upload']['type'];
if( $upload_Size == 0) {
header("Location: home_edit.php?msg=File size is ZERO!");
exit();
}
if( $upload_Mime_Type != "image/jpeg" AND $upload_Mime_Type != "image/gif" ) {
unlink($upload_Temp);
header("Location: home_edit.php?msg=Wrong type of image - only JPG or GIF");
exit();
}
//Where the file is upploaded to
$uploadFile = "../images/home".$upload_Name ;
if (!is_dir(dirname($uploadFile))) {
@RecursiveMkdir(dirname($uploadFile));
} else {
@chmod(dirname($uploadFile), 0777);
}
@move_uploaded_file( $upload_Temp , $uploadFile);
chmod($uploadFile, 0755);
mysql_query("UPDATE home SET lowercontentimage='/images/home/$upload_Name',lowercontentalt='$newimageALT',lowercontent='$newdtails' WHERE id='1'");
header("Location: main.php?msg=Content Updated");
}
?>
<html>
<head>
<title>Blah!</title>
<link rel="stylesheet" type="text/css" href="./includes/newstyle.css" />
<script type="text/javascript" src="./jscripts/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({
// General options
mode : "textareas",
//theme : "simple",
theme : "advanced",
//plugins
plugins : "emotions,phpimage,paste,directionality,fullscreen,style",
//plugins : "advimage,advlink,paste,directionality,fullscreen,imagemanager,filemanager",
// Theme options
theme_advanced_buttons1 : "bold,italic,forecolor,|,justifyleft,justifyright,justifyfull,|,charmap,|,sub,sup,|,hr,|,formatselect,fontselect,fontsizeselect,|,fullscreen",
theme_advanced_buttons2 : "cut,copy,paste,|,undo,redo,|,link,unlink,phpimage,|,emotions",
theme_advanced_buttons3 : "",
extended_valid_elements : "a[name|href|target|title|onclick]",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_layout_manager : "SimpleLayout"
});
</script>
</head>
<body>
<div id="container">
<div id="banner"><h1>Admin Interface</h1></div>
<div id="nav"><?php include './includes/nav.inc.php'; ?></div>
<div id="content">
<?php
// retrieve the row from the database
$query = "SELECT * FROM home where id='1'";
$result = mysql_query( $query );
if( $result && $home = mysql_fetch_object( $result ) ) {
// set our variables
$lowercontentalt = $home -> lowercontentalt;
$lowercontent = $home -> lowercontent;
}
//}
// print out the form
if (isset($_GET['msg'])) { echo "<div class=\"msg\"> $_GET[msg] </div>"; }
?>
<form action="<?php echo $PHP_SELF; ?>" method="post">
<br />
<table width="80%" border="1" cellpadding="3" cellspacing="0" style="font-family:arial; font-size:13px;">
<tr>
<td valign="top">Lower Box Text</td>
<td align="left" valign="top">
<textarea name="lowercontent" rows="10" style="width:100%"><?php echo $lowercontent; ?></textarea>
</td>
</tr>
<tr>
<td>Left Image<br /><?php echo $lowercontentimage; ?></td>
<td align="left" valign="top"><input type="file" name="upload" size="50">
</td>
</tr>
<tr>
<td>Image ALT text</td>
<td align="left" valign="top">
<input type="text" name="lowercontentalt" value="<?php echo $lowercontentalt; ?>" size="50" maxlength="255">
</td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" name="Submit" value="Save">
</td>
</tr>
</table>
</form>
</div>
<div id="footer"> </div>
</div>
</body>
</html>
I've left the tinymce code in just for reference.
The error I get is that the file size is zero, but the file is definately not zero. I've tried other files but I continue to get this error.
If I comment out the filesize check, there is no name for the $upload_Name so I think somehow the file is not being recognised when the form is submitted.
I've got a feeling I'll get slightly embarrassed with the solution to this but at this moment in time, I don't really care 'cos this is causing my no end of frustration!