Hello,
I have written a little script to load five images.
I guess it should be quite simple but I have done something wrong !
In the code below, when it displays the $POST elements - they
are all blank. Should I be using $FILE ?? if so how ??
I admit to being very confused about this and would appreciate any help.
The controlling and checking script is called a_picts.php and is here:
PHP Code:
if(isset($_POST['run'])){ // BIG IF
$A_ref = strip_tags(trim($_POST["adref"]));
$N_pix1 = strip_tags(trim($_POST["pix1"]));
$N_pix2 = strip_tags(trim($_POST["pix2"]));
$N_pix3 = strip_tags(trim($_POST["pix3"]));
$N_pix4 = strip_tags(trim($_POST["pix4"]));
$N_pix5 = strip_tags(trim($_POST["pix5"]));
$ctr = 0;
// Checking image in pix files.
// this just shows what is received from the form
echo "$A_ref, $N_pix1, $N_pix2, $N_pix3, $N_pix4, $N_pix5, $POST[adref],
$POST[pix1], $POST[pix2], $POST[pix3], $POST[pix4], $POST[pix5]";
if($N_pix1 != ""){
if($_FILES['pix1']['tmp_name'] == "none") {
$message1 = "Picture file did not successfully upload: Pix 1" ;
$message2 = "Check the file size. Must be less than 500K";
require_once ("a_picts_fm.php");
exit();
} // endif
if(!ereg("image",$_FILES['pix1']['type'])) {
$message1 = "The file you have selected for Picture 1 is not";
$message2 = "a recognised picture file - Please try a different file";
require_once ("a_picts_fm.php");
exit();
} // endif
$ctr = 1;
} // endif
// then this repeats for pix2 - pix 5
/
Everything seems ok - so we connect to the database and
move the images to the website.
/
$destination = 'c:\data'."\".$FILES['pix1']['name'];
$temp_file = $FILES['pix1']['tmp_name'];
move_uploaded_file($temp_file,$destination);
// then this repeats for pix2 - pix 5
echo "
<div style='position:absolute; left:120px; top:140px' >
<span style='color:blue; font-size:20px;font-weight:bold;'>
You have uploaded $ctr pictures.</span><br></div>";
exit();
} // end BIG IF
else {
$message1 = "none";
$message2 = "none";
require_once ("a_picts_fm.php");
} // end else
?>
The form that it uses is called a_picts_fm.php and is here:
PHP Code:
<div style='position:absolute; left:120px; top:120px' >
<span style="color:blue; font-size:20px;font-weight:bold; ">Adding pictures to your advert.</span><br>
Select your picture files from your computer using the browse buttons.
<br>You can have up to five pictures.<br><br>
Mess 1: <?php echo "$message1"; ?><br>
Mess 2: <?php echo "$message2"; ?>
</div>
<form name="main_fm" enctype ="multipart/form-data" action="a_picts.php" method="POST">
<input type = 'hidden' name='run' value="on">
<input type="hidden" name ="MAX FILE SIZE" value="500000">
<input type = 'hidden' name='adref' value="<?php echo $A_ref ?>">
<div id='Props_add2a' style='position:absolute; left:30px; top:200px' >
<table CELLPADDING="1" BORDER="0" >
<tr><td> <br></td></tr>
<tr>
<td>Picture 1: </td>
<td><input type="file" size="50" name="pix1"></td>
</tr>
<tr>
<td>Picture 2: </td>
<td><input type="file" size="50" name="pix2" ></td>
</tr>
<tr>
<td>Picture 3: </td>
<td><input type="file" size="50" name="pix3" ></td>
</tr>
<tr>
<td>Picture 4: </td>
<td><input type="file" size="50" name="pix4" ></td>
</tr>
<tr>
<td>Picture 5: </td>
<td><input type="file" size="50" name="pix5" ></td>
</tr>
<tr><td> <br></td></tr>
<br>
<tr><td></td>
<td><input type="submit" name="upload" value="Upload Pictures"> </td>
</tr>
</table>
</div>
The problem is that the $_POST variables pix1 - pix5 dont contain anything, I want to save them (file name and path) in a db so the webpage can show them
What have I done wrong ??? 😕
Thanks