PDA

View Full Version : image upload problem


Jamiedia
09-30-2006, 06:58 PM
Hello all,
Ive been working on a site with a script I have used thousands of times. I have never had a problem with it and I have gone over it over and over again but I cant see a problem.

This script is used to keep a simple updateable page with a display image, it seems to recognise the image but it doesnt always upload it. The script does currently work but only when you try to upload the same image twice (use the admin form twice with the same image). This has never happened before and I cant understand it. Can anyone here notice an immediate problem or offer any advice/improvement.

This is being used on a windows server (php enabled) which is the only difference to what I normally used but other than that it should work fine.

Heres the script which handles the form:

addEntry.php
<?php
function sanitise($user_input) {
while($user_input != strip_tags($user_input)) {
$user_input = strip_tags($user_input);
}
$safe_string = trim(htmlentities(stripslashes($user_input), ENT_QUOTES));
return $safe_string;
}

if($_POST['action']=='Add Entry'){
//handle image upload
if(is_uploaded_file($_FILES['image']['tmp_name']) && move_uploaded_file($_FILES['image']['tmp_name'], './images/'.$_FILES['image']['name']) && $_FILES['image']['size']<(1024*1000)){
$imagefile = './images/'.$_FILES['image']['name'];
}
//handle second image upload
//if(is_uploaded_file($_FILES['t_image']['tmp_name']) && move_uploaded_file($_FILES['t_image']['tmp_name'], './images/'.$_FILES['t_image']['name']) && $_FILES['t_image']['size']<25600){
//$t_imagefile = './images/'.$_FILES['t_image']['name'];
//}
//Add to database
$db = implode('', file('./pagedata.db'));
$_POST['entry_title']=sanitise($_POST['entry_title']);
$_POST['entry_text']=str_replace("\n", '<br />', sanitise($_POST['entry_text']));
$fh = fopen('./pagedata.db', "w");
fwrite($fh, $db.$_FILES['image']['name']."|".$_POST['entry_title']."|".$_POST['entry_text']."|".$_POST['price']."\n");
fclose($fh);
//redirect
header('Location:./');
}else{
?>
<html>
<head>
<TITLE>Page Manager</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<h2>You have arrived at this page in error. Please return to the management area.</h2>
</body>
</html>
<?php
}
?>

Any help on this would be greatly appreciated. The scripts open to use so please feel free to adapt it any way you see fit.