This thread is linked to this one : MP3 player via FTP
My main issue is that I would like some students to upload MP3 files an a dedicated server in this way :
1. They can upload MP3 (without password if possible) from a flash website (made with koolmoves v7)
2. They can not erase files on the server
There is a file upload contribution in www.Koolexchange.com it uses AS1 and was built with V6, but don't let that stop you taking a look, it works very well.
myfile= new FileReference()
mp3Filter = new FileFilter("mp3", "*.mp3");
myfile.addEventListener(ProgressEvent.PROGRESS,fstatus);
myfile.addEventListener(Event.COMPLETE,fileDone);
myfile.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
myfile.addEventListener(Event.SELECT,selectHandler);
function selectHandler(e:Event){
txt2.text=e.target.name;
}
function fstatus(e:Event){
stat.text="status:"+e.bytesLoaded+" of "+e.bytesTotal;
}
function fileDone(e:Event){
stat.text="file uploaded "+e.data;
}
function ioErrorHandler(e:Event){
stat.text="IO ERROR "+e;
}
function bFile(e:MouseEvent){
myfile.browse([mp3Filter]);
}
function sendFile(e:MouseEvent){
stat.text="Trying to send";
uploadURL = new URLRequest();
uploadURL.url="upload.php";
myfile.upload(uploadURL);
}
and the PHP code to go on your server (this is a simplfied version with no error checking)
It gets that fine, that is an named array element of the Array Filedata.
It's uploading the file fine, including the name being set, I'm just not getting a COMPLETE event.
function bFile(e:MouseEvent){
myfile.browse([mp3Filter]);
}
function sendFile(e:MouseEvent){
stat.text="Trying to send";
uploadURL = new URLRequest();
uploadURL.url="upload.php";
myfile.upload(uploadURL);
}
PHP Code:
<?php
$fileName = basename($_FILES["Filedata"]["name"]);
$ok=move_uploaded_file($_FILES["Filedata"]["tmp_name"], $fileName);
if ($ok)
{
$message = "$fileName uploaded successfully.";
}
else
{
$message = "Somthing is wrong with uploading a file.";
}
But one question how to set a different target on my server, I don't want the file to go on the root directory but in the directory called "mixages fous".
And an other one, I want people who want to upload to leave me some informations like : first name, last name, phone number, email, working location. If it could be written in a txt file on the server it would be nice.
I don't know if you can help me on this aspect but you help very much on the upload side
To post data along with the upload, you need to create some sort of form.
On the php backend you can place it in a text file, mail it to yourself or place it in a database if you have one.
Another thing you might want to consider is users uploading content with the same filename resulting in problems. To prevent that, you could add a timestamp to the filename and change the routine that creates the xml file so that it leaves the timstamp in for the url to access but removes it for the title that is being shown.
I have modified the php file and now I upload in the good directory... thanks
About the form to fullfil could you give me one last help on this.
The best feature would be to rename the file uploaded like firstname_lastname.mp3 automatically.
If there are two times the same entries it will overwrite the file on the server.
The form will increase a txt file on the server.
I would like those informations to be written in order to upload :
first name, last name, phone number, email, working location
If you have no time to develop just give me the procedure.
Thanks to your help I have created most of what I needed, I am very grateful