Results 1 to 7 of 7

Thread: PHP -

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date: Sep:2016
    Location:
    Posts: 18

    PHP -

    ! PHP, . , Word 2003, 2010 Notepad. , , , , , . - . ! PHP . :
    Code:
    <?php
    if ($_FILES['file']['name'] !=""){
    if ($_FILES['file']['name'] != ""){
       if ($_FILES['file']['type'] == "image/jpeg"){
          copy($_FILES['file']['tmp_name'], $_POST['name']) or die ("     !");
       }else{ die(" !"); }
    }else{ die("  !"); }  
    }
    #          .
    #   copy() : copy("","   ")
    #              
    ?>
    <html>
    <head>
    <title>  </title>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
    </head>
    <body>
    <?php
    $name = $_FILES['file']['name']; //
    $size = $_FILES['file']['size']; // ( )
    $type = $_FILES['file']['type']; //  
    ?>
    <a href="<?php echo ("$name"); ?>"></a>   <b><?php echo ("$size"); ?></b>    <b><?php echo ("$type"); ?></b>   !
    </body>
    </html>
    :
    Code:
    <html>
    <head>
    <title>  </title>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
    </head>
    <body>
    <form action="upload.php" method="post" enctype="multipart/form-data">
    :<input type="file" name="file" size="40"><br>
     :<input type="text" name="name" size="50">
    <input type="submit" value="">
    </form></body></html>

  2. #2
    Registered User syman's Avatar
    Join Date: Aug:2016
    Location: Sofia
    Posts: 1,232
    , MIME :
    if ($_FILES['file']['type'] == "image/jpeg"){

    , PHP. .

  3. #3
    Registered User tedych's Avatar
    Join Date: Nov:2003
    Location:
    Posts: 17,654
    - . 100 ( ) . PHP .

    is_uploaded_file($file['tmp_name']).
    ,
    if (move_uploaded_file($file['tmp_name'], $new_filename)) {... success ....} else { failure...... }.

    . . , , . , (). , .

    , MIME- . MIME-.

    ( ).
    Code:
    <?php
    $message = array(
    	'type' => 'warning',
    	'text' => '    !'
    );
    
    if (isset($_FILES['file']) && is_uploaded_file($_FILES['file']['tmp_name'])) {
    	$file = $_FILES['file'];
    	$exts = 'doc,docx,txt,jpg,jpeg,gif,png';
    	$origext = '';
    	$validext = false;
    	$lastdot = strtolower(strrpos($file['name'], '.'));
    	// check extension
    	if ($lastdot) {
    		$origext = substr($file['name'], $lastdot + 1);
    		if ($origext !== '' && strpos($origext, ',') === false) {
    			$validext = strpos($exts, $origext) !== false;
    		}
    	}
    
    	if ($validext) {
    		// determine destination path
    		$fpath = date("Y-m-d--H-i-s").DIRECTORY_SEPARATOR.$file['name'];
    		if (move_uploaded_file($file['tmp_name'], $fpath)) {
    			$message['type'] = 'success';
    			$message['text'] = " <a href=\"$fpath\">{$file['name']}</a>   {$file['size']}    \"$origext\"  .";
    		} else {
    			$message['type'] = 'error';
    			$message['text'] = '    !';
    		}
    	} else {
    	   $message['type'] = 'error';
    	   $message['text'] = ' !';
    	}
    }
    ?>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
    <title>  </title>
    <style>
    .warning {
    	color: brown;
    }
    .error {
    	color: red;
    }
    .success {
    	color: darkgreen;
    }
    </style>
    </head>
    <body>
    	<div class="<?=$message['type']?>">
    		<?=$message['text']?>
    	</div>
    </body>
    </html>

  4. #4
    Registered User
    Join Date: Sep:2016
    Location:
    Posts: 18
    Tedych, .

    - - - - - -

    , , , :

    Warning: move_uploaded_file(2016-09-07--18-29-52\Pano_1.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\xampp\htdocs\uploaddocs\upload.php on line 24

    Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\xampp\tmp\php4281.tmp' to '2016-09-07--18-29-52\Pano_1.jpg' in C:\xampp\htdocs\uploaddocs\upload.php on line 24
    ?

  5. #5
    Registered User tedych's Avatar
    Join Date: Nov:2003
    Location:
    Posts: 17,654
    , , .

    $fpath = date("Y-m-d--H-i-s").DIRECTORY_SEPARATOR.$file['name'];


    $subdir = date("Y-m-d--H-i-s");
    if (!is_dir($subdir)) mkdir('./'.$subdir, 0777, true);
    $fpath = $subdir.DIRECTORY_SEPARATOR.$file['name'];

  6. #6
    Registered User
    Join Date: Sep:2016
    Location:
    Posts: 18
    ! ! . .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |