我对此进行了广泛的搜索,但还没有真正找到解决方案。
有一位客户想要在他们的网站上播放音乐(是的,我知道..)。Flash 播放器抓取名为song.mp3 的单个文件并播放它。
好吧,我正在尝试获得功能,以便能够让客户上传他们自己的新歌曲(如果他们想要更改它)。
所以基本上,脚本需要允许他们上传文件,然后用新文件覆盖旧文件。基本上,确保 Song.mp3 的文件名保持不变。
我想我需要使用PHP来1)上传文件2)删除原始song.mp3 3)将新文件上传重命名为song.mp3
这看起来对吗?或者有更简单的方法吗?提前致谢!
编辑:我 impimented UPLOADIFY 并且能够使用
'onAllComplete' : function(event,data) {
alert(data.filesUploaded + ' files uploaded successfully!');
}
Run Code Online (Sandbox Code Playgroud)
我只是不知道如何将其指向 PHP 文件......
'onAllComplete' : function() {
'aphpfile.php'
}
Run Code Online (Sandbox Code Playgroud)
???? 哈哈
标准表格足以上传,只需记住在表格中包含哑剧。然后你可以使用 $_FILES[''] 来引用该文件。
然后您可以检查提供的文件名,并使用 file_exists() 检查文件名来查看它是否存在于文件系统中,或者如果您不需要保留旧文件,则可以使用执行文件移动并覆盖旧文件与临时目录中的新内容之一
<?PHP
// this assumes that the upload form calls the form file field "myupload"
$name = $_FILES['myupload']['name'];
$type = $_FILES['myupload']['type'];
$size = $_FILES['myupload']['size'];
$tmp = $_FILES['myupload']['tmp_name'];
$error = $_FILES['myupload']['error'];
$savepath = '/yourserverpath/';
$filelocation = $svaepath.$name.".".$type;
// This won't upload if there was an error or if the file exists, hence the check
if (!file_exists($filelocation) && $error == 0) {
// echo "The file $filename exists";
// This will overwrite even if the file exists
move_uploaded_file($tmp, $filelocation);
}
// OR just leave out the "file_exists()" and check for the error,
// an if statement either way
?>
Run Code Online (Sandbox Code Playgroud)