Bram Bram - 1 year ago 132
HTML Question

How to upload an audio file with html and php?

I am struggling with creating an audio file upload form for my website. I feel like the upload section works properly, but when I try it out and I submit the uploading it goes to the right php page, but the screen is all white with nothing on it.

My goal is to move the uploaded audio file into the uploads directory on my server.

I have the following code:

<!DOCTYPE html>

<title>File Upload Form</title>

<form action="gettfile.php" method="post" enctype="multipart/form-data">
<input type="file" name="uploadFile" id="uploadFile">
<input type="submit" value="Upload File" name="submit">
<p> testen </p>


and for the php page:

$uploads_dir = 'uploads';

$tmp_name = $_FILES["uploadFile"]["tmp_name"][$key];
$name = $_FILES["uploadFile"]["name"][$key];
move_uploaded_file($tmp_name, "$uploads_dir/$name");


Please note that I am a complete newbie with programming, so a really simple explanation would be much appreciated!

Thanks in advance

Answer Source

//whats with $key. I dont see the need for that. try the code below. And the white screen? always print some message for your test code. $uploads_dir = 'uploads';

    $tmp_name = $_FILES["uploadFile"]["tmp_name"];
    $name = $_FILES["uploadFile"]["name"];
    $moved = move_uploaded_file($tmp_name, "$uploads_dir/$name");
    if($moved && file_exists("$uploads_dir/$name")){
        echo 'file uploaded successfully';
        echo $_FILES['userfile']['error'].' -- ailed to move file';

For the second issue you are facing, You need to set the value of upload_max_filesize and post_max_size in your php.ini :

; Maximum allowed size for uploaded files. upload_max_filesize = 40M

; Must be greater than or equal to upload_max_filesize post_max_size = 40M

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download