An upload script permits users to upload a file from a client computer to the remote server. It contains two parts: the HTML form and the PHP code.
The HTML code for an upload form field is:
<form action="script.php" method="post" enctype="multipart/form-data"> <input type="file" name="field_name" /><br /> <input type="submit" name="submit" value="Submit" /> </form>- The enctype attribute of the form tag indicates that the form should be able to handle multiple types of data, including files.
<?php // If is received a valid file from the 'field_name' form field if (isset($_FILES['field_name'])) { if ($_FILES['field_name']['error'] > 0) { echo 'Error: '. $_FILES['field_name']['error']. '<br />'; } else { echo 'Upload: '. $_FILES['field_name']['name']. '<br />'; echo 'Type: '. $_FILES['field_name']['type']. '<br />'; echo 'Size: '. ($_FILES['field_name']['size'] / 1024) . ' Kb<br />'; echo 'Stored in: '. $_FILES['field_name']['tmp_name']; } } ?>Assuming that is uploaded a JPEG image (image.jpg), this code will output:
move_uploaded_file('temp_file', 'destination')- "temp_file" is the location and name of the temporary copy of the file, that is stored in $_FILES['field_name']['tmp_name']
<?php $updir = 'uploads/'; // sets the folder where the uploaded files are copied $max_size = 100; // sets maximum file size allowed (in KB) // file types allowed $allowtype = array('gif', 'jpg', 'jpeg', 'png'); // If is received a valid file from the 'field_name' form field if (isset($_FILES['field_name'])) { // check for errors if ($_FILES['field_name']['error'] > 0) { echo 'Error: '. $_FILES['field_name']['error']. '<br />'; } else { // get the name, size (in kb) and type (the extension) of the file $fname = $_FILES['field_name']['name']; $fsize = $_FILES['field_name']['size'] / 1024; $ftype = end(explode('.', strtolower($fname))); // checks if the file already exists if (file_exists($updir. $fname)) { echo 'The file: '. $fname. ' already exists'; } else { // if the file not exists, check its type (by extension) and size if (in_array($ftype, $allowtype)) { // check the size if ($fsize <= $max_size) { // uses function to copy the file from temporary folder to $updir if (!move_uploaded_file ($_FILES['field_name']['tmp_name'], $updir. $fname)) { echo 'The file '. $fname. ' could not be copied, try again'; } else { echo $fname. ' ('. $fsize. ' kb) was successfully uploaded'; } } else { echo 'The file '. $fname. ' exceeds the maximum permitted size, '. $max_size. ' KB'; } } else { echo $fname. ' - invalid file type'; } } } } ?> <form action="" method="post" enctype="multipart/form-data"> <input type="file" name="field_name" /><br /> <input type="submit" name="submit" value="Submit" /> </form>- The move_uploaded_file() function will overwrite an existing file, with the same filename, without warning, so the script checks if the file already exists (with file_exists() ), if it does not, it copies the file to the directory specified in the $updir variable (here "uploads").
<input type="checkbox" name="a_name" value="value" checked="checked" />
#id { background:url("path_to_image.png"); background-size:contain; background-repeat:no-repeat; }
var rest8_7 = 8 % 7; alert(rest8_7);
$nr = ceil(3.5); echo $nr; // 4