Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////// Html code add into abc.php
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>Single Upload Form with PHP</title>
- </head>
- <body>
- <form method="POST" action="upload.php" enctype="multipart/form-data">
- <label for="file"> Pick a file : </label>
- <input type="file" name ="file1">
- Add Watermark :
- <input type="file" name ="file2">
- <input type="submit" value = "Upload">
- </form>
- </body>
- </html>
- //////////// add into upload.php php code
- <?php
- //Check if the file is well uploaded
- if($_FILES['file1']['error'] || $_FILES['file2']['error'] > 0) { echo 'Error during uploading, try again'; }
- //We won't use $_FILES['file']['type'] to check the file extension for security purpose
- //Set up valid image extensions
- $extsAllowed = array( 'jpg', 'jpeg', 'png', 'gif' );
- //Extract extention from uploaded file
- //substr return ".jpg"
- //Strrchr return "jpg"
- $extUpload = strtolower( substr( strrchr($_FILES['file1' ]['name'] , '.') ,1) ) ;
- $extUpload1 = strtolower( substr( strrchr($_FILES['file2' ]['name'] , '.') ,1) ) ;
- //Check if the uploaded file extension is allowed
- if (in_array($extUpload, $extsAllowed, $extUpload1) ) {
- //Upload the file on the server
- $name = "./{$_FILES['file1']['name']}";
- $name1 = "./{$_FILES['file2']['name']}";
- $result = move_uploaded_file($_FILES['file1']['tmp_name'], $name);
- $result1 = move_uploaded_file($_FILES['file2']['tmp_name'], $name1);
- if($result){echo "<img src='$name'/>";}
- else { echo 'File is not valid. Please try again'; }
- if($result1){echo "<img src='$name1'/>";}
- } else { echo 'File is not valid. Please try again'; }
- ?>
Add Comment
Please, Sign In to add comment