Jump to content

Recommended Posts

Hello

 

I'm building a form to upload an mp3 and at the same time add it to a mysql database where i'll have url to the uploaded file nad lenght.

My problem is with the lenght. How can i get the lenght of the mp3?

 

I have been looking at http://www.zedwood.com/article/127/php-calculate-duration-of-mp3 and http://www.getid3.org/ but getid3 script don't work on my server due to magic quotes and the zedwood tutorial i can't understand how to get the lenght from a file on his upload.

 

My code to upload so far is:

 

form:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form action="mailer.php" method="post" enctype="multipart/form-data">
  <p><span class="sublinkbt">Titulo: </span><br />
    <br />
    <input name="title" type="text" class="txt" id="title" size="50" />
    <br />
  </p>
  <p><span class="sublinkbt">Descrição: </span>
    <label><br />
      <br />
      <textarea name="description" cols="50" rows="5" class="txt" id="description"></textarea>
    </label>
    <br />
  </p>
  <p class="txt"><span class="sublinkbt">Anexo: <br />
    </span><br />
    <input name="arquivo" type="file" class="txt" id="arquivo" size="50" />
    <br />
    <br />
    <br />
    <input type="submit" value="Enviar" name="submit" />
  </p>
</form>
</body>
</html>

 

mailer.php:

 

<?php

require_once('Connections/helderc_podcast.php');

/***************************************************\
* PHP 4.1.0+ version of email script. For more
* information on the mail() function for PHP, see
* http://www.php.net/manual/en/function.mail.php
\***************************************************/

$title = $_POST["title"];
$description = $_POST["description"];
$type = "audio/mpeg";

// O nome original do arquivo no computador do usuário  
$arqName = $_FILES['arquivo']['name'];  
// O tipo mime do arquivo. Um exemplo pode ser "image/gif"  
$arqType = $_FILES['arquivo']['type'];  
// O tamanho, em bytes, do arquivo  
$arqSize = $_FILES['arquivo']['size'];  
// O nome temporário do arquivo, como foi guardado no servidor  
$arqTemp = $_FILES['arquivo']['tmp_name'];  
// O código de erro associado a este upload de arquivo  
$arqError = $_FILES['arquivo']['error'];  


if ($arqError == 0) {  

// Verifica o tipo de arquivo enviado  
if ($_FILES['arquivo']['type'] != "audio/mpeg" && $_FILES['arquivo']['type'] != "audio/mp3"){
echo 'O tipo de arquivo enviado é inválido!';  
// Verifica o tamanho do arquivo enviado  
} else {
             
$pasta = 'mp3/';
             
// Pega a extensão do arquivo enviado
             
$extensao = strtolower(end(explode('.', $arqName)));
             
// Define o novo nome do arquivo usando um UNIX TIMESTAMP
$nome = time() . '.' . $extensao;

// Escapa os caracteres protegidos do MySQL (para o nome do usuário)
   
//$nomeMySQL = mysql_real_escape_string($_POST['nome']);
       
$upload = move_uploaded_file($arqTemp, $pasta . $nome);

$enclosureurl = "http://criativos.endbox.com/mp3/$nome";

if ($upload == true) {  

mysql_select_db($database_helderc_podcast, $helderc_podcast);

mysql_query("INSERT INTO podcast (title, description, enclosureurl, length, type) VALUES ('$title', '$description', '$enclosureurl', '$length', '$type')");

             
}  
         
}  
     
} else {  
         
echo 'Ocorreu algum erro com o upload, por favor tente novamente!';  
     
} 


?>

 

now i need to find a way to get the lenght..

Link to comment
https://forums.phpfreaks.com/topic/232961-get-mp3-lenght/
Share on other sites

What do you mean by

but getid3 script don't work on my server due to magic quotes

 

Magic quotes on or off shouldn't matter to this script.

 

Ken

 

I was trying to use the getid3 class but once i install it i got a message that says that i need to put magic quotes off..

P.S.  Learn how to spell "length".

Link to comment
https://forums.phpfreaks.com/topic/232961-get-mp3-lenght/#findComment-1198209
Share on other sites

I was trying to use the getid3 class but once i install it i got a message that says that i need to put magic quotes off..

 

See this section in the manual about how to turn them off. If you can't do it, ask your host to turn them off. As it says in this section

This feature has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged.

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/232961-get-mp3-lenght/#findComment-1198239
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.