Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Walidacja zdjęć + formularz
#5
Kod PHP:
<?php
session_start
();
require(
"config.php");

/*
     *
     * @ Multiple File upload script.
     *
     * @ Can do any number of file uploads
     * @ Just set the variables below and away you go
     *
     * @ Author: Kevin Waterson
     *
     * @copywrite 2008 PHPRO.ORG
     *
     */

    
error_reporting(E_ALL);
 
    
/*** the upload directory ***/
    
$upload_dir'/uploads/';

    
/*** numver of files to upload ***/
    
$num_uploads 2;

    
/*** maximum filesize allowed in bytes ***/
    
$max_file_size  1048576;

    
/*** a message for users ***/
    
$msg 'Please select files for uploading';

    
/*** an array to hold messages ***/
    
$messages = array();

    
/*** check if a file has been submitted ***/
    
if(isset($_FILES['userfile']['tmp_name']))
    {
        
/** loop through the array of files ***/
        
for($i=0$i count($_FILES['userfile']['tmp_name']);$i++)
        {

            
// check if there is a file in the array
            
if(!is_uploaded_file($_FILES['userfile']['tmp_name'][$i]))
            {
                
$messages[] = 'No file uploaded @';
            }
            
// check the file is less than the maximum file size
            
elseif($_FILES['userfile']['size'][$i] > $max_file_size)
            {
                
$messages[] = "File size exceeds $max_file_size limit";
            }
            else
            {   
                
                
// copy the file to the specified dir 
                
if(move_uploaded_file($_FILES['userfile']['tmp_name'][$i],$_SERVER['DOCUMENT_ROOT'].$upload_dir.$_FILES['userfile']['name'][$i]))
                {
                    
/*** give praise and thanks to the php gods ***/
                    
$messages[] = $_FILES['userfile']['name'][$i].' uploaded';
                }
                else
                {
                    
/*** an error message ***/
                    
$messages[] = 'Uploading '.$_FILES['userfile']['name'][$i].' Failed';
                }
            }
        }
    }

?>


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
    <script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
</head>
<body>
  


<div class="message">
     <h3><?php echo $msg?></h3>
     <p>
     <?php
        
if(sizeof($messages) != 0)
        {
            foreach(
$messages as $err)
            {
                echo 
$err.'<br />';
            }
        }
     
?>
     </p>
</div>

<form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" enctype="multipart/form-data">
    <p>News Title:</p>
    <input type="text" name="article_title"/><br />

    <p>Wybierz zdjęcia:</p>
     <?php
        $num 
0;
        while(
$num $num_uploads)
        {
            echo 
'<input type="file" name="userfile[]"><br />';
            
$num++;
        }
     
?>
    <br />
    <input type="submit" name="submit">
    <input type="reset" value="Reset">
</form>

          
</body>
</html> 
Odpowiedz


Wiadomości w tym wątku
Walidacja zdjęć + formularz - przez harvester2001 - 21-03-2014, 22:33
RE: Walidacja zdjęć + formularz - przez Engine - 22-03-2014, 14:45
RE: Walidacja zdjęć + formularz - przez Engine - 22-03-2014, 17:46
RE: Walidacja zdjęć + formularz - przez harvester2001 - 22-03-2014, 20:52
RE: Walidacja zdjęć + formularz - przez Engine - 23-03-2014, 01:16

Podobne wątki…
Wątek: Autor Odpowiedzi: Wyświetleń: Ostatni post
  Jak zrobic Formularz Kontaktowy na stronie ? Kodarth 191 255,841 06-04-2021, 16:25
Ostatni post: zerin
  Weryfikacja zdjęć na stronie widzaceoko 0 1,706 19-02-2018, 02:26
Ostatni post: widzaceoko
  Jak zrobić prostą przeglądarkę zdjęć? messi19125 3 4,308 21-07-2014, 02:41
Ostatni post: Kartofelek
  php formularz - wszystkie pola muszą być wypełnione d3d3d3 2 3,636 01-10-2013, 14:16
Ostatni post: Kartofelek
  [PHP] Formularz mailowy - wysyłanie wiadomości spolprog 7 6,495 05-09-2013, 17:13
Ostatni post: Engine

Skocz do:


Użytkownicy przeglądający ten wątek: 1 gości
Sponsorzy i przyjaciele
SeoHost.pl