1.

Solve : [PHP] 'forward' value to other php file?

Answer»

I'm not sure exactly what this is called, but when I explain it should be come clear. I have an index.php file, which the user INPUTS several VALUES on.

How do i get my values to 'forward' to another php file based in what radio they picked.

Here is the Index.php file, proceeded by the upload.php

Index.php
Code: [Select]<link rel="stylesheet" type="text/css" href="style.css" media="screen" />



<center>

<font size=5>The Notebook</font>



<div id="nav">

<br />
<form method="post" action="./upload.php" enctype="multipart/form-data">

<label for="file">Upload:</label> <input type="file" name="userfile" id="file">
<input type='radio' name='class' VALUE='Science'>Science
<input type='radio' name='class' value='Mathematics'>Mathematics
<input type='radio' name='class' value='Languages'>Languages
<input type='radio' name='class' value='Fine Arts'>Fine Arts
<button>Upload</button>
</form>

<br />

</div>



<div id="nav">


</div>


Here is the upload.php file:
Code: [Select]<?php
// Configuration - Your Options

$allowed_filetypes = array('.txt','.doc','.xls','.pdf'); // These will be the types of file that will pass the validation.

$max_filesize = 524288; // Maximum filesize in BYTES (currently 0.5MB).

$upload_path = './notes/'; // The place the files will be uploaded to (currently a 'files' directory).

$filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension).

$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.

echo "Class is: " . $_FILES['class'] . "<br />";
// Check if the filetype is allowed, if not DIE and inform the user.

if(!in_array($ext,$allowed_filetypes))

die('The file you attempted to upload is not allowed.');

// Now check the filesize, if it is too large then DIE and inform the user.

if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)

die('The file you attempted to upload is too large.');

// Check if we can upload to the specified path, if not DIE and inform the user.

if(!is_writable($upload_path))

die('You cannot upload to the specified directory, please CHMOD it to 777.');

// Upload the file to your specified path.

if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename))

echo 'Your file upload was successful, view the file <a href="' . $upload_path . $filename . '" TITLE="Your File">here</a>'; // It worked.

else

echo 'There was an error during the file upload.&#160; Please try again.'; // It failed :(.

?>

The vars i want to forward are in the first on index.php

You can see the current file at :

http://textingwhile.free-site-host.com/NoteServ/Index.php
http://textingwhile.free-site-host.com/NoteServ/upload.php
See here: http://www.w3schools.com/php/php_file_upload.aspRadio buttons are POSTED as their name.

so to get the value of the radio button that was selected you would do something LIKE this:

Code: [Select]$usrRadio = $_POST['class'];

if ($usrRadio == 'Science')
{
      //Do Sciency code
}
if ($usrRadio == 'Mathematics')
{
      //Do mathematicsy code
}

Etc.  Get it?

Hope that helps.

-rockOn upload.php put

Code: [Select]$userfile = isset($_POST['userfile']) ? $_POST['userfile'] : '';
if you ever want to pass variables using "get" juct change the post to _GET .


Is this what you wanted?



Discussion

No Comment Found