Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Upload de imagem para pasta images e após o envio ele mostra o caminho (path)
- <?php
- if(isset($_FILES['image'])){
- $errors= array();
- $file_name = $_FILES['image']['name'];
- $file_size = $_FILES['image']['size'];
- $file_tmp = $_FILES['image']['tmp_name'];
- $file_type = $_FILES['image']['type'];
- $file_ext=strtolower(end(explode('.',$_FILES['image']['name'])));
- $extensions= array("jpeg","jpg","png");
- if(in_array($file_ext,$extensions)=== false){
- $errors[]="extension not allowed, please choose a JPEG or PNG file.";
- }
- if($file_size > 2097152) {
- $errors[]='File size must be excately 2 MB';
- }
- if(empty($errors)==true) {
- move_uploaded_file($file_tmp,"images/".$file_name);
- echo "Success";
- }else{
- print_r($errors);
- }
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Image Upload</title>
- </head>
- <body>
- <form action="" method="post" enctype="multipart/form-data">
- <input type="file" name="image" accept="image/*">
- <input type="submit" value="Upload">
- </form>
- <?php if(isset($file_name)) echo "Image path: " . "images/" . $file_name; ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement