Hello all-
Have the following code, and I want to take the array of names more likely 1-10 photo's I am uploading and want them to be saved as a formname.formname_1 -10.jpg etc. How would I convert the array to rename these photo's appropriately and ten save into the photo1 through 10 position in my sql insert call? Any help is greatly appreciated.
I'm thinking $photo1=photo_1.jpg etc.. just not sure what functions to use? ereg_replace or?
<-Form.html->
<form method="post" action="upload.php" enctype="multipart/form-data">
<input name="userfile[]" type="file">
<input name="userfile[]" type="file">
<input name="userfile[]" type="file">
<input name="userfile[]" type="file">
<input name="userfile[]" type="file">
<input name="userfile[]" type="file">
<input type="submit" value="Upload!!!" >
</form>
<-Upload.php->
<?
for($i=0;$i<sizeof($userfile);$i++)
{
if(!$userfile_size[$i])
continue;
$UPLOAD = fopen( $userfile[$i], "r" );
$contents = fread( $UPLOAD,$userfile_size[$i]);
fclose( $UPLOAD );
$SAVEFILE = fopen( "upload//".$userfile_name[$i], "wb" );
fwrite( $SAVEFILE, $contents,$userfile_size[$i] );
fclose( $SAVEFILE );
}
@ $db = mysql_pconnect("localhost", "root", "");
if (!$db)
{
echo "Error: Could not connect to database. Please try again later.";
exit;
}
mysql_select_db("waterfront");
$query = "insert into waterfront values ('".$agent_id."', '".$layout."', '".$page."', '".$position."', '".$text."', '".$address."', '".$city."', '".$state."', '".$zip."', '".$bedrooms."', '".$bathrooms."', '".$price."', '".$mls."', '".$instructions."', '".$userfile_name."', '".$photo2."', '".$photo3."', '".$photo4."', '".$photo5."', '".$photo6."', '".$photo7."', '".$photo8."', '".$photo9."', '".$photo10."')";
$result = mysql_query($query);
if ($result)
echo "Server HaD Receive the Upload Files!";
?>