Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form id="insert_movie" action="upload_file.php" method="post" enctype="multipart/form-data">
- <label for="file">Filename:</label>
- <input type="file" name="file" id="file"><br>
- <input type="submit" name="submit" value="Submit">
- </form>
- //Upload the image
- $allow = array("jpg", "jpeg", "gif", "png");
- $todir = 'images/';
- if(isset($_POST['submit'])){
- if ( !!$_FILES['file']['tmp_name'] ) // is the file uploaded yet?
- {
- $info = explode('.', strtolower( $_FILES['file']['name']) ); // whats the extension of the file
- if ( in_array( end($info), $allow) ) // is this file allowed
- {
- if ( move_uploaded_file( $_FILES['file']['tmp_name'], $todir . basename($_FILES['file']['name'] ) ) )
- {
- echo "this doesn't work";
- }
- }
- else
- {
- // error this file ext is not allowed
- echo "this doesn't work either";
- }
- }
- }
- echo "however this works perfectly";
- ?>
- if ( !!$_FILES['file']['tmp_name'] ) // is the file uploaded yet?
- if ( $_FILES['file']['tmp_name'] ) // is the file uploaded yet?
- <?php
- //Upload the image
- $allow = array("jpg", "jpeg", "gif", "png");
- $todir = 'images/';
- if(isset($_POST['submit'])){
- // if ( !!$_FILES['file']['tmp_name'] ) // is the file uploaded yet?
- if ( $_FILES['file']['tmp_name'] ) // is the file uploaded yet?
- {
- $info = explode('.', strtolower( $_FILES['file']['name']) ); // whats the extension of the file
- if ( in_array( end($info), $allow) ) // is this file allowed
- {
- if ( move_uploaded_file( $_FILES['file']['tmp_name'], $todir . basename($_FILES['file']['name'] ) ) )
- {
- echo "Success";
- }
- }
- else
- {
- // error this file ext is not allowed
- echo "Sorry, this is now allowed.";
- }
- }
- }
- // echo "however this works perfectly";
- ?>
- enctype="multipart/form-data"
- $path = dirname(__FILE__).'/'.$todir;
- if(is_dir($path)){
- if ( move_uploaded_file( $_FILES['file']['tmp_name'], $path . basename($_FILES['file']['name'] ) ) )
- {
- echo "this doesn't work";
- }
- }
- else
- echo 'Check path '.$path;
- if(isset($_POST['submit'])){
- //not sure if what you wrote here was valid, but most commonly it's
- if (isset($_FILES['file']['name']) ) // does file exist
- {
- //we'll use an easier way to find the extension
- $filename = $_FILES['file']['name'];
- $ext = pathinfo($filename, PATHINFO_EXTENSION);
- if ( in_array( $ext, $allow) ) // is this file allowed
- {
- if ( move_uploaded_file( $_FILES['file']['tmp_name'], $todir . basename($_FILES['file']['name'] ) ) )
- {
- echo "file uploaded";
- }
- else
- {
- echo 'error uploading: '.$_FILES['file']['error'];
- }
- }
- else
- {
- // error this file ext is not allowed
- echo "file not allowed";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement