Forum Moderators: coopster

Message Too Old, No Replies

FTP Upload Problem

         

compose

9:37 am on Mar 16, 2006 (gmt 0)

10+ Year Member



Hi,

I am makng a video uplaod script,using FTP functions of php. but each time it is givng error that upload failed.

when i host script to local sever it is uploading files to my web server. But when i hosted script on my web server and runs it each time it is falling in condition that,file uplad failed.

below is the code that, i am using in script


<?
if(isset($_POST['submit']))
{
$conn_id = ftp_connect('myserver.com');

// login with username and password
$login_result = ftp_login($conn_id,'usrName', 'password');

// check connection
if ((!$conn_id) ¦¦ (!$login_result)) {
echo "FTP connection has failed!";
exit;
} else {
echo "Connected to server!";
}

// upload the file
$file = $_POST['userfile'];

$dir = "/public_html/$file";
$upload = ftp_put($conn_id, $dir, "$file", FTP_BINARY);

// check upload status
if (!$upload)
{
echo "FTP upload has failed!";
}
else
{
echo "Uploaded $file to myserver.com";
}
// close the FTP stream */
ftp_close($conn_id);
?>

Can any body help me in debug it.

Regards,

Vineet

omoutop

10:14 am on Mar 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



$dir = "/public_html/$file";?

You will have a dir with name /public_html/my_name.mpg?

I think you mean $dir = "/public_html/"; :)
In that case try $dir = dir("/public_html/");
Also check read/write mode in your folder, else try to chmod(0777) it.

Try to use something like
if (is_dir($dir))
{
// execute
}
else
{
echo $dir." is not a folder";
}

compose

11:05 am on Mar 16, 2006 (gmt 0)

10+ Year Member



Thanx for reply,

But actually $dir is not denoting Directory on web server it is name of remote file with remote path.

And i tried also what u said, but that is also not working. :(

please help.

vineet

omoutop

11:34 am on Mar 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I cant offer any more help other than this:

in php manual, there is a user contributed function that dos what you want

[gr.php.net...]
(one of the first ones from user kiwo1)

Hope this helps

compose

1:29 pm on Mar 16, 2006 (gmt 0)

10+ Year Member



Thanx omoutop,

this is working now, i missed to place [enctype="multipart/form-data" ] attribute in form tag.

Thanx.

vineet