can someone please give adviced on how i could put an upload box for my website,so record labels could upload directly to my website, please help me with the code or explanation of how to do it.thank you all for what you do for othere people

Dani AI

Generated

For : correctly pointed out that the browser only supplies the file control and you need server code to save uploads; 's PHP question is a good direction since many hosts support it. Below is a compact, practical starting point and a short production checklist so uploads from record labels are safe and reliable.

<?php
// upload-handler.php - minimal example; harden before production
$uploadDir = __DIR__ . '/uploads/';
if (!is_dir($uploadDir)) mkdir($uploadDir, 0755, true);

if (empty($_FILES['file']) || $_FILES['file']['error'] !== UPLOAD_ERR_OK) {
    http_response_code(400);
    exit('Upload error');
}

$tmp  = $_FILES['file']['tmp_name'];
$name = basename($_FILES['file']['name']);
$ext  = strtolower(pathinfo($name, PATHINFO_EXTENSION));

$allowedExt = ['mp3','wav','flac','aiff'];
if (!in_array($ext, $allowedExt)) {
    http_response_code(415);
    exit('Invalid file type');
}

$finfo = new finfo(FILEINFO_MIME_TYPE);
$mime  = $finfo->file($tmp);
$mimeAllowed = ['audio/mpeg','audio/wav','audio/x-wav','audio/flac'];
if (!in_array($mime, $mimeAllowed)) {
    http_response_code(415);
    exit('MIME mismatch');
}

$dest = $uploadDir . uniqid('track_', true) . '.' . $ext;
if (!move_uploaded_file($tmp, $dest)) {
    http_response_code(500);
    exit('Could not save file');
}

echo 'Upload OK';
?>

Notes and checklist

  • Set upload_max_filesize and post_max_size in php.ini and handle $_FILES error codes; see the PHP manual for details (PHP file uploads).
  • Validate file type by inspecting contents (finfo) not just extension. OWASP has a practical checklist for secure uploads (OWASP File Upload Cheat Sheet).
  • Store uploads outside the webroot or block execution with server rules, give non-executable permissions, log metadata, scan files for malware, and require authentication for label uploads.
  • For client-side input details, refer to the MDN docs on the file input element (MDN input file).

Recommended Answers

All 4 Replies

To create an upload box use the code below. You will need to have a program on your server to save the file. Hence "/cgi/bin/some-script.cgi". There is no auto magical way to upload from the client. You have to process this using server code like php, java, etc...

<form method=post name=upform action="/cgi-bin/some-script.cgi" enctype="multipart/form-data">
<input type="file" id="uploadfile"  name="uploadfile" />
<br />
<input type=button name="Submit" value="Submit" />
</form>

can someone please give adviced on how i could put an upload box for my website,so record labels could upload directly to my website, please help me with the code or explanation of how to do it.thank you all for what you do for othere people

are you using php?

I've used Java, PHP and ASP. Most Internet Service Providers support PHP at no extra cost to you. It is not that hard to learn and a google search should provide you with a pre-made solution.

What tools are you using to create web pages?

Basically this is how it works. The code I sent will give you an upload box on your page. When the user hits submit the file is sent to the server. You need some kind of program on the server to receive this and save it.

I've used Java, PHP and ASP. Most Internet Service Providers support PHP at no extra cost to you. It is not that hard to learn and a google search should provide you with a pre-made solution.

What tools are you using to create web pages?

Basically this is how it works. The code I sent will give you an upload box on your page. When the user hits submit the file is sent to the server. You need some kind of program on the server to receive this and save it.

i was askin alexberr;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.