Ok, I've been hacking at this code for two days, I can't get it to do what I want.
I just want to be able to upload 6 images, tell which uploader the image came from, and assign it an ID according to which box it was uploaded from.
Examples: upload box1 --> uploader.php --> 1_img.jpg
upload box3 --> uploader.php --> 3_img.jpg
It works when you initially fill up the ftp folder with the images starting from 1 to 6.
Then if you go back and try to upload a different image, it will override the last one.
Example: (previous one upload box3 --> uploader.php --> 3_img.jpg)
error here: upload box1 --> uploader.php --> 3_img.jpg
retry: upload box1 --> uploader.php --> 1_img.jpg (WORKS 2nd time)
I thought it was a refresh problem, but after talking to etully, I managed to have the form page automatically refresh after calling uploader.php, but the problem is still there.
When you hit submit, it submits the image to the previous one you worked on, you hit submit again, and it gets assigned the right ID. So you have to hit submit twice for it to work, and you get the old file overridden as well, which is bad.
I've run out of ideas, I've tried everything:
Here is my form code:
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<input name="uploadedfile" type="file" /><br>
<input type="submit" value="submit" />
<input type="hidden" name="picID" value="h1"/>
</form>
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<input name="uploadedfile" type="file" /><br>
<input type="submit" value="submit" />
<input type="hidden" name="picID" value="h2"/>
</form>
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<input name="uploadedfile" type="file" /><br>
<input type="submit" value="submit" />
<input type="hidden" name="picID" value="h3"/>
</form>
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<input name="uploadedfile" type="file" /><br>
<input type="submit" value="submit" />
<input type="hidden" name="picID" value="h4"/>
</form>
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<input name="uploadedfile" type="file" /><br>
<input type="submit" value="submit" />
<input type="hidden" name="picID" value="h5"/>
</form>
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<input name="uploadedfile" type="file" /><br>
<input type="submit" value="submit" />
<input type="hidden" name="picID" value="h6"/>
</form>
<?
// Connect to DATABASE
$conn = mysql_connect("localhost","*****","*****");
// Connect to Table and stores connection as variable: conn
$db = mysql_select_db("*****_academicPrograms", $conn);
// Queries the user input data with the database data
$result = MYSQL_QUERY("SELECT * from academicPrograms")
or die ("Data not found");
$worked = mysql_fetch_array($result);
switch ($_POST['picID']) {
case 'h1':
$result = MYSQL_QUERY("UPDATE academicPrograms SET pictureID = 1");
break;
case 'h2':
$result = MYSQL_QUERY("UPDATE academicPrograms SET pictureID = 2");
break;
case 'h3':
$result = MYSQL_QUERY("UPDATE academicPrograms SET pictureID = 3");
break;
case 'h4':
$result = MYSQL_QUERY("UPDATE academicPrograms SET pictureID = 4");
break;
case 'h5':
$result = MYSQL_QUERY("UPDATE academicPrograms SET pictureID = 5");
break;
case 'h6':
$result = MYSQL_QUERY("UPDATE academicPrograms SET pictureID = 6");
break;
default:
print 'None of the cases reached.';
break;
} // End: switch ($_POST['hidden'])
?>
and here's my uploader.php
<?
// Connect to DATABASE
$conn = mysql_connect("localhost","*****","*****");
// Connect to Table and stores connection as variable: conn
$db = mysql_select_db("*****_academicPrograms", $conn);
// Queries the user input data with the database data
$result = MYSQL_QUERY("SELECT * from academicPrograms")
or die ("Data not found");
// Gets boolean value of whether the query worked
$worked = mysql_fetch_array($result);
// Gets all values from table and stores them as variables
$pictureID = $worked[pictureID];
// Connects to Database for uploading image through FTP
$ftpconn = ftp_connect("*****") or die("Could not connect");
ftp_login($ftpconn,"*****","*****");
// The Directory the file will be placed
$target_path = "Images/academicPrograms/";
echo '4';
// I think the problem is here
switch ($pictureID)
{
case 1:
$uniqueName = "1_img.jpg";
//echo 'Case 1 Reached';
break;
case 2:
$uniqueName = "2_img.jpg";
//echo 'Case 2 Reached';
break;
case 3:
$uniqueName = "3_img.jpg";
//echo 'Case 3 Reached';
break;
case 4:
$uniqueName = "4_img.jpg";
//echo 'Case 4 Reached';
break;
case 5:
$uniqueName = "5_img.jpg";
//echo 'Case 5 Reached';
break;
case 6:
$uniqueName = "6_img.jpg";
//echo 'Case 6 Reached';
break;
default:
echo "No cases matched";
}
//Assigns a the path and the name together
$uniqueID= $target_path.$uniqueName;
//Moves to temp file to the targetpath
$_FILES['uploadedfile']['tmp_name'];
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $uniqueID)) {include("new.php");}
else{
echo "There was an error uploading the file, please try again!";
}
?>
Does anyone have any idea where I'm going wrong?