Problm uploading files (Trough ftp)
Moderator: General Moderators
- Luis Almeida
- Forum Commoner
- Posts: 33
- Joined: Tue Apr 01, 2003 4:22 am
Problm uploading files (Trough ftp)
I have the folowing problem, I use this code to upload files to my server (Sambar):
<?php
if(!empty($_POST['uploadfile']))
{
$filepathname = $_POST['uploadfile'];
$filename = basename($filepathname);
$uid = '******';
$pwd = '*******';
$host = '*********';
$ftp = ftp_connect($host) or die("Couldn't connect to $host");
ftp_login($ftp,$uid,$pwd) or die("Couldn't log in to $host");
ftp_chdir($ftp,"/");
if(ftp_put($ftp,$filename,$filepathname,FTP_BINARY))
{
ftp_close($ftp);
print("<META HTTP-EQUIV='Refresh' CONTENT='1;url=$_SERVER['PHP_SELF']'>");
}
else
{
die("<br>Could not transfer $filename to $host<br>");
}
}
else
{
echo "teste1";
The problem is this code works well on my PC (The one with the server) but when I try using this code on the intranet or over the internet it doesn't work, could someone help me please?
<?php
if(!empty($_POST['uploadfile']))
{
$filepathname = $_POST['uploadfile'];
$filename = basename($filepathname);
$uid = '******';
$pwd = '*******';
$host = '*********';
$ftp = ftp_connect($host) or die("Couldn't connect to $host");
ftp_login($ftp,$uid,$pwd) or die("Couldn't log in to $host");
ftp_chdir($ftp,"/");
if(ftp_put($ftp,$filename,$filepathname,FTP_BINARY))
{
ftp_close($ftp);
print("<META HTTP-EQUIV='Refresh' CONTENT='1;url=$_SERVER['PHP_SELF']'>");
}
else
{
die("<br>Could not transfer $filename to $host<br>");
}
}
else
{
echo "teste1";
The problem is this code works well on my PC (The one with the server) but when I try using this code on the intranet or over the internet it doesn't work, could someone help me please?
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
- Luis Almeida
- Forum Commoner
- Posts: 33
- Joined: Tue Apr 01, 2003 4:22 am
With "It doesn't work" I mean that "It doesn't work"
this lines of code work just fine:
but when it comes to the transfer itself
the ftp_put function returns false and I dont understand why, because like I said the code works well on my PC (The one with the server) but when I try using this code on the intranet or over the internet it doesn't work.
It just doesn´t upload anything (not even one byte)
this lines of code work just fine:
Code: Select all
ftp = ftp_connect($host) or die("Couldn't connect to $host");
ftp_login($ftp,$uid,$pwd) or die("Couldn't log in to $host");
ftp_chdir($ftp,"/");Code: Select all
ftp_put($ftp,$filename,$filepathname,FTP_BINARY);It just doesn´t upload anything (not even one byte)
I have a suspicion that you are trying to access a directory that your not supposed to, the ftp_chdir() method returns false if it's unable to change the directory.
I suspect this because you are trying to change to the root ("/", not as in the user root, but probably owned by root!) directory of the HDD you are on, which may be outside of your users agreed access.
Just a thought.
Regards,
To add:
To check if you are in your chosen directory use:
http://uk2.php.net/manual/en/function.ftp-pwd.php
I suspect this because you are trying to change to the root ("/", not as in the user root, but probably owned by root!) directory of the HDD you are on, which may be outside of your users agreed access.
Just a thought.
Regards,
To add:
To check if you are in your chosen directory use:
http://uk2.php.net/manual/en/function.ftp-pwd.php
- Luis Almeida
- Forum Commoner
- Posts: 33
- Joined: Tue Apr 01, 2003 4:22 am
- Luis Almeida
- Forum Commoner
- Posts: 33
- Joined: Tue Apr 01, 2003 4:22 am
Can you try listing the files in the dir:
What version of PHP are you using?
Code: Select all
<?php
ftp_nlist($ftp, '/');
?>Can you show us the state of your variables, add some debug code to echo out the values of $filepathname and $filename.
Also, enable some of the debug features of PHP (in case they are turned off, esp. in a production env.):
BTW, the $php_errormsg is only applicable if you have enabled "track_errors", it is disabled by default (0).
Ref:
http://uk.php.net/manual/en/ref.errorfu ... ack-errors
http://uk.php.net/manual/en/language.op ... ontrol.php
Regards,
Also, enable some of the debug features of PHP (in case they are turned off, esp. in a production env.):
Code: Select all
error_reporting(E_ALL);
ini_set('display_errors', TRUE);Ref:
http://uk.php.net/manual/en/ref.errorfu ... ack-errors
http://uk.php.net/manual/en/language.op ... ontrol.php
Regards,
- Luis Almeida
- Forum Commoner
- Posts: 33
- Joined: Tue Apr 01, 2003 4:22 am
Thats correct CACTUS, after adding:
I get the following error message:
Now I dont understand WHY, because I´m the administrator of my computer and it still works on the PC with the server installed on it
Code: Select all
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
?>Code: Select all
Warning: ftp_put(): error opening C:\TEMP\Onlyin.pps in G:\sambar60\docs\upload_last.php on line 22- Luis Almeida
- Forum Commoner
- Posts: 33
- Joined: Tue Apr 01, 2003 4:22 am
- Luis Almeida
- Forum Commoner
- Posts: 33
- Joined: Tue Apr 01, 2003 4:22 am
Ok, I found something very strange.....
Let me try to explain it
It won't be easy......
the thing is.....
1 - I´m currently working on a IntraNet
2 - There are two PC´s
3 - PC number One is the one with the server installed on it and whre the script works just fine
4 - PC number two is the one from wich I can´t upload anything
I found the following
the error message :
Warning: ftp_put(): error opening C:\TEMP\Onlyin.pps in G:\sambar60\docs\upload_last.php on line 22
is because whe I try to upload a file from PC number TWO it will try to upload the file from PC number ONE wich means tha the reference to the file is to the PC with the SEERVER installed (PC numer ONE)
How can I correct this ???
Let me try to explain it
It won't be easy......
the thing is.....
1 - I´m currently working on a IntraNet
2 - There are two PC´s
3 - PC number One is the one with the server installed on it and whre the script works just fine
4 - PC number two is the one from wich I can´t upload anything
I found the following
the error message :
Warning: ftp_put(): error opening C:\TEMP\Onlyin.pps in G:\sambar60\docs\upload_last.php on line 22
is because whe I try to upload a file from PC number TWO it will try to upload the file from PC number ONE wich means tha the reference to the file is to the PC with the SEERVER installed (PC numer ONE)
How can I correct this ???