Jump to content

Picture Upload to Certian Folder when button pressed...


bizerk

Recommended Posts

Alright so basically I have Three Submit buttons and a image uploader with user verifcation. What i want to happen is when you press the button that says "Submit Pictures", it will upload pictures to the "files/pictures/" directory, when you press "Submit School", it will upload files to the "files/school/" directory, and when you press "Submit Random", it will upload to the "files/random" directory. I made the script so that right now if the user and password are correct it wil upload to the directory "/files". Can anyone tell me what to do from the script i have so far:

 

<?

$lol = rand(1,100);
$browser = $REMOTE_ADDR;
$name = $_POST['name'];
$password = $_POST['password'];
$Submit = $_POST['Submit'];
$Submitschool = $_POST['Sschool'];
$Submitrandom = $_POST['Srandom'];
function uploadFiles($key)
{
$lol = rand(1,100);

copy ($_FILES[$key]['tmp_name'], "files/$lol".$_FILES[$key]['name'])
or die ("Error Occured When Uploading Image File to Directory");
echo "<br><u><b>File: {$_FILES[$key]['name']} Status</u></b><br><br>
File Size: {$_FILES[$key]['size']}<br>
File Type: {$_FILES[$key]['type']}<br>
<br><br>
File {$_FILES[$key]['name']} was uploaded Succesfully.<br>";
echo"<br> Click <a href='files/pictures/'>here</a> to see your files<br>";
}

if($_POST['Submit']) {
if($name =="test123" && $password =="lawlzzz" || $name=="rofl" && $password=="lolzorz")
{
foreach ($_FILES as $key=>$file)
		{
		if (!empty($file['name']))
			{
			uploadFiles($key);
			}
}
		}else{
		echo "Wrong Credentials, Please try to Login Again";
		}
		}
?>

 

So once again... how would i make it so if i had three buttons:

 

 <input type="submit" name="Spictures" value="Submit PICTURES" />
            </p>
        <p align="center"><input type="Sschool" name="Submit" value="Submit SCHOOL STUFF" />
         </p>
        <p align="center">
          <input type="submit" name="Srandom" value="Submit Random" />

 

What would i need to do to make my script so it uploads the FILES to the specific directory when the button is pressed :/

Link to comment
Share on other sites

You would need to incorporate javascript, and have the form actions depend on the button pushed.

 

the school submit button could have a onClick="submitSchool()" attribute, and so on.

 

The javascript functions could make the browser submit the info to    formprocess.php?type=school    type=random  type=pictures

 

etc :)

 

And then you could pull that variable from the URL and have your process.php page know which branch to upload to, based on that variable

Link to comment
Share on other sites

Actually, I rethought my answer, and I decided I don't like it haha. I wouldn't even go that far. This can have such a simple solution...

 

Why have 3 submit buttons? Why not have ONE submit button, and just make use of 3 radio buttons, one for each action you want?

 

<input type="radio" name="uploadwhere" value="pictures"> Pictures<br>
<input type="radio" name="uploadwhere" value="school"> School<br>
<input type="radio" name="uploadwhere" value="random"> Random<br>

 

Then, one the process page, just use:

 

$_GET['uploadwhere'];

 

to find out which of the 3 was chosen, and build your if/switch statements around that :)

 

 

 

I'm sorry, I'm not very good at giving exact answers with codes... I just explain how I would solve it. Hopefully you understand what I outlined above. If you want to wait a bit, I am sure another person will help you out here :)

Link to comment
Share on other sites

ah yeah that is a lot easier. I am not as good at JAVA as i am at php. alright well i understand that, but last time i tried radio buttons it didn't work well :/. Anyone give me an example of how to use a IF with radiobutton instance?

Link to comment
Share on other sites

Can anyone give me an example of how I would make a script that if a radio button lets say named 'pictures' is pressed and is submitted how would I make it so if that radio button was selected

 

copy blablabla etc.?

Link to comment
Share on other sites

  • 2 years later...

Alright so basically I have Three Submit buttons and a image uploader with user verifcation. What i want to happen is when you press the button that says "Submit Pictures", it will upload pictures to the "files/pictures/" directory, when you press "Submit School", it will upload files to the "files/school/" directory, and when you press "Submit Random", it will upload to the "files/random" directory. I made the script so that right now if the user and password are correct it wil upload to the directory "/files". Can anyone tell me what to do from the script i have so far:

 

<?

$lol = rand(1,100);
$browser = $REMOTE_ADDR;
$name = $_POST['name'];
$password = $_POST['password'];
$Submit = $_POST['Submit'];
$Submitschool = $_POST['Sschool'];
$Submitrandom = $_POST['Srandom'];
function uploadFiles($key)
{
$lol = rand(1,100);

copy ($_FILES[$key]['tmp_name'], "files/$lol".$_FILES[$key]['name'])
or die ("Error Occured When Uploading Image File to Directory");
echo "<br><u><b>File: {$_FILES[$key]['name']} Status</u></b><br><br>
File Size: {$_FILES[$key]['size']}<br>
File Type: {$_FILES[$key]['type']}<br>
<br><br>
File {$_FILES[$key]['name']} was uploaded Succesfully.<br>";
echo"<br> Click <a href='files/pictures/'>here</a> to see your files<br>";
}

if($_POST['Submit']) {
if($name =="test123" && $password =="lawlzzz" || $name=="rofl" && $password=="lolzorz")
{
foreach ($_FILES as $key=>$file)
		{
		if (!empty($file['name']))
			{
			uploadFiles($key);
			}
}
		}else{
		echo "Wrong Credentials, Please try to Login Again";
		}
		}
?>

 

So once again... how would i make it so if i had three buttons:

 

 <input type="submit" name="Spictures" value="Submit PICTURES" />
            </p>
        <p align="center"><input type="Sschool" name="Submit" value="Submit SCHOOL STUFF" />
         </p>
        <p align="center">
          <input type="submit" name="Srandom" value="Submit Random" />

 

What would i need to do to make my script so it uploads the FILES to the specific directory when the button is pressed :/

 

I had the same problem I solved it with more then one forms

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.