通过PHP上传歌曲

通过PHP上传歌曲,php,uploading,Php,Uploading,我制作了一个用于上传歌曲的API,但它造成了问题。当我通过android设备上传歌曲时,它会上传到Ubuntu上的歌曲文件夹中,但这首歌不会播放。请给我答案 我的代码是: <?php include('connect.php'); header("Content-type: text/xml"); $target_path = "./Songs/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['na

我制作了一个用于上传歌曲的API,但它造成了问题。当我通过android设备上传歌曲时,它会上传到Ubuntu上的歌曲文件夹中,但这首歌不会播放。请给我答案

我的代码是:

<?php

include('connect.php');
header("Content-type: text/xml");

$target_path = "./Songs/";

$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";

    chmod ("Songs/".basename( $_FILES['uploadedfile']['name']), 0644);
} 
else
{
    echo "There was an error uploading the file, please try again!";

    echo "filename: " .  basename( $_FILES['uploadedfile']['name']);

    echo "target_path: " .$target_path;
}

?>

我已经做了,而且效果很好

<?php

$target_path = "./Songs/";

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

//Get the uploaded file information

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

//get the size of the file

$size_of_uploaded_file = $_FILES["uploadedfile"]["size"]/1024;//size in KBs

//get the file extension of the file

$type_of_uploaded_file = substr($name_of_uploaded_file, strrpos($name_of_uploaded_file, '.') + 1);

//echo $size_of_uploaded_file;

$max_allowed_file_size = 10000; // size in KB

//Validations

if($size_of_uploaded_file>$max_allowed_file_size )
{

  $errors .= "\n Size of file should be less than $max_allowed_file_size";

  echo $errors;

  exit();

}

$allowed_extensions = array("mp3");

//------ Validate the file extension -----

$allowed_ext = false;

for($i=0; $i < sizeof($allowed_extensions); $i++)
{

  if(strcasecmp($allowed_extensions[$i],$type_of_uploaded_file) == 0)
  {

    $allowed_ext = true;

  }

}

if(!$allowed_ext)
{

  $errors ="The uploaded file is not supported file type");

  echo 'not a song. Error = '.$errors;

  exit();

}
   $t_remaining = $time_remaining-$duration_of_song ;

  if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) 
  {

        // perform any operation 

    echo "successfully uploaded";

        chmod ("Songs/". basename( $_FILES['uploadedfile']['name']), 0777);

} 
else
{

    echo "error in uploading";

}

我已经做了,而且效果很好

<?php

$target_path = "./Songs/";

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

//Get the uploaded file information

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

//get the size of the file

$size_of_uploaded_file = $_FILES["uploadedfile"]["size"]/1024;//size in KBs

//get the file extension of the file

$type_of_uploaded_file = substr($name_of_uploaded_file, strrpos($name_of_uploaded_file, '.') + 1);

//echo $size_of_uploaded_file;

$max_allowed_file_size = 10000; // size in KB

//Validations

if($size_of_uploaded_file>$max_allowed_file_size )
{

  $errors .= "\n Size of file should be less than $max_allowed_file_size";

  echo $errors;

  exit();

}

$allowed_extensions = array("mp3");

//------ Validate the file extension -----

$allowed_ext = false;

for($i=0; $i < sizeof($allowed_extensions); $i++)
{

  if(strcasecmp($allowed_extensions[$i],$type_of_uploaded_file) == 0)
  {

    $allowed_ext = true;

  }

}

if(!$allowed_ext)
{

  $errors ="The uploaded file is not supported file type");

  echo 'not a song. Error = '.$errors;

  exit();

}
   $t_remaining = $time_remaining-$duration_of_song ;

  if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) 
  {

        // perform any operation 

    echo "successfully uploaded";

        chmod ("Songs/". basename( $_FILES['uploadedfile']['name']), 0777);

} 
else
{

    echo "error in uploading";

}

当你说“不播放”时,你的意思是在服务器上还是流式传输到设备上,比如Android设备?上传成功了吗?当你说“不播放”时,你是指在服务器上还是流式传输到设备上,比如Android设备?上传成功了吗?此代码工作正常,可以在服务器上上传歌曲。当我在进入存储所有歌曲的特定文件夹后尝试播放这首歌曲时,我想说的是,它播放得很好,这意味着它上传得很好。这段代码运行良好,可以在服务器上上传歌曲。当我去了存储所有歌曲的特定文件夹后,尝试播放这首歌时,它播放得很好,这意味着它上传得很好。