bizerk Posted October 2, 2006 Share Posted October 2, 2006 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! Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted October 2, 2006 Share Posted October 2, 2006 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. Quote Link to comment Share on other sites More sharing options...
bizerk Posted October 2, 2006 Author Share Posted October 2, 2006 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 { Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted October 2, 2006 Share Posted October 2, 2006 as far as I can tell (and I didn't pour over your code), you should be doing fine. If it doesn't work, shout back with errors or problems. Try to make your question a little less nebulous, though. Quote Link to comment Share on other sites More sharing options...
bizerk Posted October 2, 2006 Author Share Posted October 2, 2006 Alright so wait, i should just do what i did with my FORM image uploads but replace with my radio buttons and direct it to a different function.. cause that did not work... explain to me what i should do please Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted October 2, 2006 Share Posted October 2, 2006 if checking that radio should do something totally different, just put an if statement for the radio button in your code that does one thing, then else does what it used to do... make sense? Quote Link to comment Share on other sites More sharing options...
bizerk Posted October 2, 2006 Author Share Posted October 2, 2006 Yes But what if i want several radio buttons to differnet portals so would i just make a lot of IF statements all saying ELSE to the same public upload? Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted October 2, 2006 Share Posted October 2, 2006 well, if the only difference is where it goes, then pass the radio'ed variable to your move_uploaded_file function as the directory name to move the file to -- no if statements required.of course, you'd need to have a default radio button already selected. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.