Page 1 of 1
Uploading files via php to var/lib
Posted: Thu Sep 30, 2010 10:05 am
by chrisatnetronix
I have written a script to upload to the path var/lib/asterisk/sounds/ but it will not read the uploader.php via the path i provided ion the action, how can i resolve this
code:
<form enctype="multipart/form-data" action="var/lib/asterisk/sounds/uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
Re: Uploading files via php to var/lib
Posted: Thu Sep 30, 2010 10:15 am
by DigitalMind
Are you sure you didn't miss the leading /?
Why did you put your script into Asterisk's subdirectory for sound files?
Usually this directory is owned by asterisk user and you don't have permissions to write there anything.
Re: Uploading files via php to var/lib
Posted: Thu Sep 30, 2010 10:16 am
by chrisatnetronix
All I need is a way to upload the sound wav to the asterisk sounds folder via php, any help would be great.
Re: Uploading files via php to var/lib
Posted: Thu Sep 30, 2010 10:18 am
by chrisatnetronix
I even tried
/var/lib/asterisk/sounds/uploader.php
and it shows the ip /var/lib/asterisk/sounds/uploader.php in the address bar in the browser
gives me 404
Re: Uploading files via php to var/lib
Posted: Thu Sep 30, 2010 10:20 am
by DigitalMind
Your uploader.php must be located in any www directory.
Show the code of your uploader.php
Re: Uploading files via php to var/lib
Posted: Thu Sep 30, 2010 10:24 am
by chrisatnetronix
<?php
$target_path = "/";
$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";
} else{
echo "There was an error uploading the file, please try again!";
}
Re: Uploading files via php to var/lib
Posted: Thu Sep 30, 2010 10:39 am
by DigitalMind
must be :
Code: Select all
$target_path = "/var/lib/asterisk/sounds/";
but take care about permissions.
Re: Uploading files via php to var/lib
Posted: Thu Sep 30, 2010 10:41 am
by chrisatnetronix
chmod var/lib/asterisk/sounds to 777
and set target to what you suggested and get:
There was an error uploading the file, please try again!
Re: Uploading files via php to var/lib
Posted: Thu Sep 30, 2010 10:46 am
by DigitalMind
BTW remove basename()
Re: Uploading files via php to var/lib
Posted: Thu Sep 30, 2010 10:51 am
by DigitalMind
Add as following
Code: Select all
...
} else{
echo "There was an error uploading the file, please try again!\n";
echo "Error: " . $_FILES['uploadedfile']['error'] . "\n";
}
Re: Uploading files via php to var/lib
Posted: Thu Sep 30, 2010 10:53 am
by chrisatnetronix
removed baseline data
<?php
$target_path = "/var/lib/asterisk/sounds/";
$target_path = $target_path . ;
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". .
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>
shows nothing
Re: Uploading files via php to var/lib
Posted: Thu Sep 30, 2010 10:55 am
by DigitalMind
See my post above.
P.S. Use
Code: Select all
for your code
P.P.S. I'll be back after English lesson (in a few hours) :)
Re: Uploading files via php to var/lib
Posted: Thu Sep 30, 2010 10:56 am
by chrisatnetronix
There was an error uploading the file, please try again! Error: 2
but i had to add baseline back to get that error
Re: Uploading files via php to var/lib
Posted: Thu Sep 30, 2010 10:59 am
by DigitalMind
2 = UPLOAD_ERR_FROM_SIZE
hint: see MAX_FILE_SIZE
Re: Uploading files via php to var/lib
Posted: Thu Sep 30, 2010 11:25 am
by chrisatnetronix
works, your the man, i am retarded:)