내 사이트 구성원이 고객이들을 수 있도록 짧은 음악 샘플을 업로드 할 수있는 기본 스크립트가 있습니다.공백을 업로드 된 파일의 밑줄로 바꾸기
일부 파일 이름에는 샘플을 재생할 때 분명히 문제를 일으키는 공백이 있습니다. 임시 디렉토리에 업로드하는 것과 파일을 'samples'디렉토리로 옮기는 것 사이에 이러한 공백을 밑줄로 대체하는 방법이 있습니까?
$filename = trim(addslashes($_FILES['userfile']['name']));
쓰기 :이 선 후
<?
$url = "http://domain.com/uploads/samples/";
//define the upload path
$uploadpath = "/home/public_html/uploads/samples";
//check if a file is uploaded
if($_FILES['userfile']['name']) {
$filename = trim(addslashes($_FILES['userfile']['name']));
//move the file to final destination
if(move_uploaded_file($_FILES['userfile']['tmp_name'],
$uploadpath."/". $filename)) {
echo "
bla bla bla, the final html output
";
} else{
if ($_FILES['userfile']['error'] > 0)
{
switch ($_FILES['userfile']['error'])
{
case 1: echo 'File exceeded upload_max_filesize'; break;
case 2: echo 'File exceeded max_file_size'; break;
case 3: echo 'File only partially uploaded'; break;
case 4: echo 'No file uploaded'; break;
}
exit;
}
}
}
?>
'str_replace'는 (검색, 대체, 제목)'입니다. –
그 덕분에, 고마워! –