2012-03-13 2 views
0

업로드 노래용 API를 만들었지 만 문제가 발생합니다. 내 안드로이드 장치를 통해 노래를 업로드하면 우분투의 노래 폴더에 업로드되지만이 노래는 재생되지 않습니다. 제게 해결책을주세요.PHP를 통해 업로드 된 노래

<?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; 
} 

?> 
+0

'재생 안함'이라고 말하면 서버에서 또는 Android 기기와 같은 기기로 스트리밍 하시겠습니까? 업로드가 성공적 이었습니까? – halfer

답변

3

나는 그것을 수행하고 작동이 잘되는 :

내 코드는 이것이다.

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

} 
+0

이 코드는 잘 작동하고 서버에 노래를 업로드하고 있습니다. 그리고 내가 모든 노래가 저장된 특정 폴더의 위치로 이동 한 후에이 노래를 연주하려고 시도했을 때 그것을 뺨에 대고, 그것은 잘 재생된다는 것을 의미합니다. – chandan

관련 문제