Jump to content

Quick Question regarding Radio Buttons with PHP


bizerk

Recommended Posts

Okay so I have an upload site where users can upload an image. At first i made it simple and made it so users can upload an image and it is sent to their USER DIRECTORY and to a PUBLIC DIRECTORY. Now what i want to happen is to add radio buttons with different PORTAL NAMES on it where the file will be sent. So for example:

if the user wants to upload picture: "lol.jpg" and they check the "mainportal" radio button than i want it to use a function that i previousley made that will check it's size and do all that crap and than SEND it to their user directory/mainportal. Here is the script of the form, and where i think i need to put the radio button script, but I DONT KNOW how to manipulate the radio  buttons so it calls the script...

[code]<input type="hidden" name="MAX_FILE_SIZE" value="' . $uploadmax . '" />
          Overwrite existing image(s)? Yes<input type="checkbox" name="overwrite_file" value="true" /><br />
  <br>
  Which Portal to send Files:
  <br>
  <label>
      <input type="radio" name="mainportal" value="main">
      Main Portal</label>
  <br>
  <input type="file" name="imgupload_one" /><br />
  <input type="file" name="imgupload_two" /><br />
  <input type="file" name="imgupload_three" /><br />
  <input type="file" name="imgupload_four" /><br />
  <input type="file" name="imgupload_five" /><br />
  <input type="file" name="imgupload_six" /><br />
  <input type="file" name="imgupload_seven" /><br />
  <input type="file" name="imgupload_eight" /><br />
  <input type="submit" name="upload_image" value="Upload Image(s)" /><br />
  <br />
<align="center">Click<a href="/more.php/"> here</a> to upload MORE pictures.
  </form></p>';
}[/code]


Okay so that script makes it call up the function "upload". And here is where i define that function:

[code]function upload($user_dat, $globalvars)
{
$this->display_space($user_dat, $globalvars);

if(isset ($_POST['upload_image']))
{
if($_FILES['imgupload_one']['name'] != null)
{
$this->upload_transfer($user_dat, $globalvars, 'imgupload_one');
} else {
echo "You must select at least one image to upload!<br />";
}

if($_FILES['imgupload_two']['name'] != null)
{
$this->upload_transfer($user_dat, $globalvars, 'imgupload_two');
}

if($_FILES['imgupload_three']['name'] != null)
{
$this->upload_transfer($user_dat, $globalvars, 'imgupload_three');
}

if($_FILES['imgupload_four']['name'] != null)
{
$this->upload_transfer($user_dat, $globalvars, 'imgupload_four');

}

if($_FILES['imgupload_five']['name'] != null)
{
$this->upload_transfer($user_dat, $globalvars, 'imgupload_five');
}

if($_FILES['imgupload_six']['name'] != null)
{
$this->upload_transfer($user_dat, $globalvars, 'imgupload_six');

}
if($_FILES['imgupload_seven']['name'] != null)
{
$this->upload_transfer($user_dat, $globalvars, 'imgupload_seven');

}
if($_FILES['imgupload_eight']['name'] != null)
{
$this->upload_transfer($user_dat, $globalvars, 'imgupload_eight');

}
//here is where i think i should put the radio buttons IF statements.
}[/code]

So yeah above after all the img_upload defines is where i am thinking i should put the IF statement, but i don't know what exactly to put. PLEASE HELP!
Link to comment
Share on other sites

Maybe I misunderstand the question. You already have the code working, so you're just adding an if statement to the end, right? wouldn't it just be [code=php:0]if($_POST['mainportal']=="main") ...[/code] Of course, you'd also have to redo all of those if statements for each upload.

Better solution would be to make a loop:
[code=php:0]do {
if($_FILES[key($_FILES)]['name'] != null) {
$this->upload_transfer($user_dat, $globalvars, key($_FILES));
}
}while(next($_FILES));[/code]


Now, what upload_transfer() does is a mystery (since you didn't include it here). If it does all the validation stuff to the file AND moves it with move_upload_files to someplace, then your additional if statement might not work because the original file has moved already.
Link to comment
Share on other sites

Here is the upload_transfer function, but i was not concerned about the img_uploads. What i wanted to do was just make a new function called mainupload_function and have it executed when some highlighted the RADIO BUTTON MAIN PORTAL. here is the main upload function script:

[code]function upload_graffiti($user_dat, $globalvars, $whichfile)
{
$error_occured = false;

echo "<i>" . $_FILES[$whichfile]['name'] . " upload status</i>:<br />";

switch($_FILES[$whichfile]['error'])
{
case 1:
$error_occured = true;
echo "The image you attempted to upload exceeds the max file size limit in the PHP configuration file. Please either reduce  your image size, or contact an administrator and ask them to expand file size<br />";
break;

case 2:
$error_occured = true;
echo "The image you attempted to upload exceeds the max file size limit set by the admin.<br />";
break;
}

$split_ext = explode(',', $globalvars->settings['allowed_ext']);
$split_img = explode('.', $_FILES[$whichfile]['name']);
$extcount = count($split_ext);

for($i=0;$i<$extcount;$i++)
{
$invalidimg = true;
$split_values = explode(':', $split_ext[$i]);
$i_values = $extcount - 1;

if($split_values[0] == strtolower($split_img[1]) && $split_values[1] == "allow")
{
$invalidimg = false;
$i = $extcount + 1000;
} elseif($i == $i_values && $split_values[0] != strtolower($split_img[1]))
{
// If the image was valid, we would have exited by now.
$error_occured = true;
}
}

if(is_dir($user_dat['usrdir']))
{
$sql_dirlimit = explode(':', $globalvars->settings['directory_limit']);

switch($sql_dirlimit[1])
{
case MB:
$dirsize_set = new functions();
$dirsize = $dirsize_set->mb_bytes($sql_dirlimit[0]);
break;

case KB:
$dirsize_set = new functions();
$dirsize = $dirsize_set->kb_bytes($sql_dirlimit[0]);
break;
}

if($user_dat['usedspace'] < $dirsize)
{
if(file_exists($user_dat['usrdir'] . "/" . $_FILES[$whichfile]['name']))
{
if($_POST['overwrite_file'] == true)
{
unlink($user_dat['usrdir'] . "/" . $_FILES[$whichfile]['name']);
} else {
$error_occured = true;

echo "The image you attempted to upload already exists!<br />Please select to overwrite exisiting images, or rename the image you're attempting to upload.<br /><br />";
}
}
} else {
$error_occured = true;
echo "You have used up all your directory space.<br />";
}
} else {
$error_occured = true;

echo "Your directory is non-existant. Please contact an adminstrater.<br />";
}

if($error_occured != true)
{


if(move_uploaded_file ($_FILES[$whichfile]['tmp_name'], $user_dat['usrdir'] . "/" . $_FILES[$whichfile]['name']))
{
$file = $user_dat['name'] . "-" . $split_img[0] . "." . strtolower($split_img[1]);
$destination2 = "portals/graffiti/$file";

rename($user_dat['usrdir'] . "/" . $_FILES[$whichfile]['name'], $user_dat['usrdir'] . "/" . $split_img[0] . "." . strtolower($split_img[1]));
copy($user_dat['usrdir'] . "/" . $split_img[0] . "." . strtolower($split_img[1]), $destination2);
echo "Your image was uploaded successfully. ";
echo "Click " . '<a href="users/' . $user_dat['name'] . "/" . $split_img[0] . "." . strtolower($split_img[1]) . '" target="_blank">here</a>' . " to view your image.";
} else {
echo "An unknown error occured.";
}
} else {
if($invalidimg == true)
{
echo "The type of image you attempted to upload is not allowed for upload.";
}
}

echo "<br />----------------------------------------------------------------------------------------------<br />";
}[/code]

All of it works and should work as long as i find a way to make the RADIO Button execute this function. This is the part that is different than the original function "upload_transfer"

if(move_uploaded_file ($_FILES[$whichfile]['tmp_name'], $user_dat['usrdir'] . "/" . $_FILES[$whichfile]['name']))
{
$file = $user_dat['name'] . "-" . $split_img[0] . "." . strtolower($split_img[1]);
$destination2 = "portals/graffiti/$file";

rename($user_dat['usrdir'] . "/" . $_FILES[$whichfile]['name'], $user_dat['usrdir'] . "/" . $split_img[0] . "." . strtolower($split_img[1]));
copy($user_dat['usrdir'] . "/" . $split_img[0] . "." . strtolower($split_img[1]), $destination2);
echo "Your image was uploaded successfully. ";
echo "Click " . '<a href="users/' . $user_dat['name'] . "/" . $split_img[0] . "." . strtolower($split_img[1]) . '" target="_blank">here</a>' . " to view your image.";
} else {
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.