Upload image and temp file errors

I have a script that is trying to upload files to a folder on the server and also a tmp file and I’m getting the errors below:


Warning: move_uploaded_file(imgdata/socks/) [function.move-uploaded-file]: failed to open stream: Is a directory in /websites/123reg/LinuxPackage22/ni/ce/so/nicesocks.co.uk/public_html/admin/admin_stock.php on line 238

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpWWCkO6' to 'imgdata/socks/' in /websites/123reg/LinuxPackage22/ni/ce/so/nicesocks.co.uk/public_html/admin/admin_stock.php on line 238

I thought it might be permissions and have changed the folders related to these to 777 and still a problem.

Here is the code related to it:


//Image 1
$pic1= $random1 . ($_FILES['image1']['name']);
if (($_FILES['image1']['name']) == "") {
$target = "imgdata/socks/";	
} else {
$target = "imgdata/socks/" . $pic1;
}
//$target = $target . basename( $_FILES['image1']['name']);

//Image 2
$pic2= $random2 . ($_FILES['image2']['name']);
if (($_FILES['image2']['name']) == "") {
$target = "imgdata/socks/";	
} else {
$target2 = "imgdata/socks/" . $pic2;
}
//$target2 = "imgdata/stock/";
//$target2 = $target2 . basename( $_FILES['image2']['name']);
//$pic2=($_FILES['image2']['name']);

//Image 3
$pic3= $random3 . ($_FILES['image3']['name']);
if (($_FILES['image3']['name']) == "") {
$target = "imgdata/socks/";	
} else {
$target3 = "imgdata/socks/" . $pic3;
}
//$target3 = "imgdata/stock/";
//$target3 = $target3 . basename( $_FILES['image3']['name']);
//$pic3=($_FILES['image3']['name']);

//Image 4
$pic4= $random4 . ($_FILES['image4']['name']);
if (($_FILES['image4']['name']) == "") {
$target = "imgdata/socks/";	
} else {
$target4 = "imgdata/socks/" . $pic4;
}

								
$q=mysql_query("insert into stock (short_Title, long_Title, ladies_Checkbox, mens_Checkbox, kids_Checkbox, equestrian_Checkbox, walking_Checkbox, boot_Checkbox, wellie_Checkbox, fashion_Checkbox, over_Checkbox, ref_Number, Description, Price, in_Stock, image_1, image_2, image_3, image_4, paypal_Path, stock_Active) values('$shortTitle','$longTitle','$ladiesCheckbox','$mensCheckbox','$kidsCheckbox','$equCheckbox','$walkingCheckbox','$bootCheckbox','$wellieCheckbox','$fashionCheckbox','$overCheckbox','$refNumber','$description','$price','$inStock','$target1','$target2','$target3','$target4','$paypalPath','$stockActive')") or die (mysql_error());


//Writes the photos to the server
move_uploaded_file($_FILES['image1']['tmp_name'], $target);
move_uploaded_file($_FILES['image2']['tmp_name'], $target2);
move_uploaded_file($_FILES['image3']['tmp_name'], $target3);
move_uploaded_file($_FILES['image4']['tmp_name'], $target4);

<tr>
<td bgcolor="#A0B050" width="161">
<div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Stock Image 1 (Main):</div>
</td>
<? if(isset($_GET['stock_Id'])) { ?>
<td bgcolor="#888888">
<? if ($rows["image_1"] == "imgdata/socks/") { ?>
<p style="position:relative; font-family:'Times New Roman', Times, serif; font-size:14px; line-height:20px; margin-top:7px;">There is no image selected for 'Image Area 1', 'browse' below to select an image to upload.</p>
<? } else { ?>
<img src="<?= $rows["image_1"];?>" height="120px" style="border:#FFFFFF solid 1px; position:relative; float:left; left:1px; margin-top:3px; clear:both;"><br/><br/><br/><br/><br/><br/><br/>
<? } ?>
<input type="file" name="image1" size="64"><span style="color:#990000 ; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11;"> - Browse to change 'Image 1'</span>
<input type="hidden" name="image1b" value="<?= $rows["image_1"];?>">
</td>
</tr>
<? } else { ?>
<td bgcolor="#888888">
<input type="file" name="image1" size="64">
</td>
</tr>
<? } ?>


As I’m only trying to upload1 file at the moment, the error line code relates to:


move_uploaded_file($_FILES['image1']['tmp_name'], $target);

The filename to move is missing in the first error.
Again you second error is missing a filename to save to.

I recomend echoing all your variables to see if the contain what you expect them to contain.

OK I think I got it sorted thanks,

I got a few of the variables the wrong way around, school boy error!

Cheers