0
<form enctype="multipart/form-data" action="upload_file.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" name="submit" value="Upload File" />
</form>

<?php
// Where the file is going to be placed 
$target_path = "uploads/";

/* Add the original filename to our target path.  
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 


$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if ($_REQUEST["submit"] == "Upload File")
{
    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
    {
        echo "The file ".  basename( $_FILES['uploadedfile']['name']). " has been uploaded";
    }
    else
    {
        echo "There was an error uploading the file, please try again!";
    }
}
?>

Notice: Undefined index: uploadedfile in C:\wamp\www\E_Systems\upload_file.php on line 13

Notice: Undefined index: uploadedfile in C:\wamp\www\E_Systems\upload_file.php on line 18

Notice: Undefined index: submit in C:\wamp\www\E_Systems\upload_file.php on line 20

Can successful upload the image into "uploads" folder, but still showing error.
Please help me..

3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by ElaineTeo
0

file 1

    <form enctype="multipart/form-data" action="upload_file.php" method="POST">
    <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
    Choose a file to upload: <input name="uploadedfile" type="file" /><br />
    <input type="submit" name="submit" value="Upload File" />
    </form>

file 2 (upload_file.php)

    <?php
    $target_path = "uploads/";
    if ($_REQUEST["submit"] == "Upload File")

        $target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
        if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
        {
                echo "The file ".  basename( $_FILES['uploadedfile']['name']). " has been uploaded";
        }
        else
        {
            echo "There was an error uploading the file, please try again!";
        }
    }
    ?>
0

If this is all in one file, you'll get an error on page load as you haven't submitted the form yet. It is not advisable to send form data to itself/same page.

<?php
if(isset($_POST['submit'])){
    $target_path = "uploads/";
    /* Add the original filename to our target path.  
    Result is "uploads/filename.extension" */
    $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
    $target_path = "uploads/";
    $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
        if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)){
            echo "The file ".  basename( $_FILES['uploadedfile']['name']). " has been uploaded";
        }else{
            echo "There was an error uploading the file, please try again!";
        }
    }
}
?>

You could try that. Check you have write rights to that folder.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.