Uploading files via php to var/lib

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chrisatnetronix
Forum Newbie
Posts: 16
Joined: Mon Jul 19, 2010 8:13 pm

Uploading files via php to var/lib

Post 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>
User avatar
DigitalMind
Forum Contributor
Posts: 152
Joined: Mon Sep 27, 2010 2:27 am
Location: Ukraine, Kharkov

Re: Uploading files via php to var/lib

Post 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.
chrisatnetronix
Forum Newbie
Posts: 16
Joined: Mon Jul 19, 2010 8:13 pm

Re: Uploading files via php to var/lib

Post 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.
chrisatnetronix
Forum Newbie
Posts: 16
Joined: Mon Jul 19, 2010 8:13 pm

Re: Uploading files via php to var/lib

Post 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
User avatar
DigitalMind
Forum Contributor
Posts: 152
Joined: Mon Sep 27, 2010 2:27 am
Location: Ukraine, Kharkov

Re: Uploading files via php to var/lib

Post by DigitalMind »

Your uploader.php must be located in any www directory.
Show the code of your uploader.php
chrisatnetronix
Forum Newbie
Posts: 16
Joined: Mon Jul 19, 2010 8:13 pm

Re: Uploading files via php to var/lib

Post 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!";
}
User avatar
DigitalMind
Forum Contributor
Posts: 152
Joined: Mon Sep 27, 2010 2:27 am
Location: Ukraine, Kharkov

Re: Uploading files via php to var/lib

Post by DigitalMind »

Code: Select all

$target_path = "/";
must be :

Code: Select all

$target_path = "/var/lib/asterisk/sounds/";
but take care about permissions.
chrisatnetronix
Forum Newbie
Posts: 16
Joined: Mon Jul 19, 2010 8:13 pm

Re: Uploading files via php to var/lib

Post 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!
User avatar
DigitalMind
Forum Contributor
Posts: 152
Joined: Mon Sep 27, 2010 2:27 am
Location: Ukraine, Kharkov

Re: Uploading files via php to var/lib

Post by DigitalMind »

BTW remove basename()
User avatar
DigitalMind
Forum Contributor
Posts: 152
Joined: Mon Sep 27, 2010 2:27 am
Location: Ukraine, Kharkov

Re: Uploading files via php to var/lib

Post 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";
}
Last edited by DigitalMind on Thu Sep 30, 2010 10:54 am, edited 1 time in total.
chrisatnetronix
Forum Newbie
Posts: 16
Joined: Mon Jul 19, 2010 8:13 pm

Re: Uploading files via php to var/lib

Post 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
User avatar
DigitalMind
Forum Contributor
Posts: 152
Joined: Mon Sep 27, 2010 2:27 am
Location: Ukraine, Kharkov

Re: Uploading files via php to var/lib

Post 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) :)
chrisatnetronix
Forum Newbie
Posts: 16
Joined: Mon Jul 19, 2010 8:13 pm

Re: Uploading files via php to var/lib

Post 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
User avatar
DigitalMind
Forum Contributor
Posts: 152
Joined: Mon Sep 27, 2010 2:27 am
Location: Ukraine, Kharkov

Re: Uploading files via php to var/lib

Post by DigitalMind »

2 = UPLOAD_ERR_FROM_SIZE
hint: see MAX_FILE_SIZE
chrisatnetronix
Forum Newbie
Posts: 16
Joined: Mon Jul 19, 2010 8:13 pm

Re: Uploading files via php to var/lib

Post by chrisatnetronix »

works, your the man, i am retarded:)
Post Reply