Page 1 of 1
Uploading audio to 2 separate folders:
Posted: Fri Nov 12, 2010 7:13 am
by chrismicro
I have created an uploader script I need it to upload to 2 separate folders on the system:
here is my code for uploading to one folder:
Code: Select all
$target_path = "/var/lib/asterisk/sounds/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$filename = $_FILES['uploadedfile']['name'];
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
I also need it to upload to
Code: Select all
/srv/www/htdocs/k2zwf6jks9yx6zhs6vr06842jj51fx/
how do i do this?
Re: Uploading audio to 2 separate folders:
Posted: Fri Nov 12, 2010 11:49 am
by Celauran
Use
copy() instead of move_uploaded_file()?
Re: Uploading audio to 2 separate folders:
Posted: Sat Nov 13, 2010 7:05 am
by chrismicro
I am not sure i Understand, where do I put the 2nd target path?
Re: Uploading audio to 2 separate folders:
Posted: Sat Nov 13, 2010 7:11 am
by Celauran
Either call the copy function twice, or copy once followed by move_uploaded_file once.
Code: Select all
$target_path = "/var/lib/asterisk/sounds/";
$backup_path = "/srv/www/htdocs/k2zwf6jks9yx6zhs6vr06842jj51fx/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$backup_path .= basename( $_FILES['uploadedfile']['name']);
$filename = $_FILES['uploadedfile']['name'];
if (copy($_FILES['uploadedfile']['tmp_name'], $target_path) && copy($_FILES['uploadedfile']['tmp_name'], $backup_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
Re: Uploading audio to 2 separate folders:
Posted: Sat Nov 13, 2010 8:18 am
by chrismicro
sweet works awesome, your the man
Re: Uploading audio to 2 separate folders:
Posted: Sun Nov 14, 2010 9:24 pm
by chrismicro
how can i take the code above and make it so that if i upload a file of the same name it will not do this and show an error?
Re: Uploading audio to 2 separate folders:
Posted: Mon Nov 15, 2010 6:06 am
by Celauran
Depends what you want to happen to the existing file. You could try using
shell_exec() to rename the existing file, or you could rename the new file, say by appending .1 to the end.
Re: Uploading audio to 2 separate folders:
Posted: Mon Nov 15, 2010 10:28 am
by chrismicro
could you show me code wise, so i can better understand?
Re: Uploading audio to 2 separate folders:
Posted: Mon Nov 15, 2010 10:55 am
by Celauran
Rename the existing file using shell_exec:
Code: Select all
if (file_exists($target_path . $filename))
{
shell_exec("mv " . $target_path . $filename . " " . $target_path . $filename . ".1");
}
Re: Uploading audio to 2 separate folders:
Posted: Tue Nov 16, 2010 6:07 pm
by chrismicro
what about just giving an error instead of renaming the file?
Re: Uploading audio to 2 separate folders:
Posted: Tue Nov 16, 2010 6:56 pm
by Celauran
Code: Select all
if (file_exists($target_path . $filename))
{
echo "Error: A file called {$filename} already exists in {$target_path}";
}
Or am I not understanding your question?