Undefined index - audio upload

Asked

Viewed 85 times

0

I have a small code to upload audio, but is showing Undefined index error in two lines referring to "audioFile".

Notice: Undefined index: audioFile in C: xampp apps wordpress htdocs upload.php on line 5

Notice: Undefined index: audioFile in C: xampp apps wordpress htdocs upload.php on line 6

I found several similar questions but could not solve the problem. In these queries, most of the time the problem was in the "enctype" statement, which I believe is not my case.

Follows the code:

php form.

<html>
<head>
<meta charset="utf-8">
<title>Upload de audio</title>
</head>

<body>
     
    <form action="upload.php" method="POST" enctype="multipart/form-data">
    <input type="file" name="audioFile"/>
    <input type="submit" value="Upload Audio" name="save_audio"/>
    </form>
</body>
</html>

upload.php

<?php
if(isset($_POST['save_audio']) && $_POST['save_audio'] == "Upload Audio")
{
    $dir='uploads/';
    $audio_path=$dir.basename($_FILES['audioFile']['name']);
    if(move_uploaded_file($_FILES['audioFile']['tmp_name'],$audio_path))
    {
        echo 'upload ok';
    }
}
?>

Obs.: The uploads folder is in the same path as the pages shown here.

  • The sample code you put to me worked me perfectly. However attention to the file size sent, this cannot be bigger than the upload_max_filesize defined in php.ini, which by default is usually 2M

  • I also thought it was the file and tested with different files, one of them has 1.4Mb and also was not. Thanks for the reply.

  • You tagged the tag wordpress - that file upload.php is within your theme?

  • It is out of the theme. These pages I am testing are in a directory previous to C themes: xampp apps wordpress htdocs. Since the theme is in C: xampp apps wordpress htdocs wp-content themes

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.