Page 1 of 3
Problm uploading files (Trough ftp)
Posted: Tue Jun 17, 2003 6:10 am
by Luis Almeida
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?
Posted: Tue Jun 17, 2003 6:22 am
by twigletmac
What do you mean by 'it doesn't work'?
Mac
Posted: Tue Jun 17, 2003 6:26 am
by rashed
If you please write the error/warning message
Posted: Tue Jun 17, 2003 9:11 am
by Luis Almeida
With "It doesn't work" I mean that "It doesn't work"
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,"/");
but when it comes to the transfer itself
Code: Select all
ftp_put($ftp,$filename,$filepathname,FTP_BINARY);
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)
Posted: Tue Jun 17, 2003 9:32 am
by cactus
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
Posted: Wed Jun 18, 2003 4:42 am
by Luis Almeida
the ftp_chdir() method works fine because it returns ( 1, true) and the scripts also works fine if I call it from the PC with the server installed on but when it comes to execut it fron another PC on the Intranet or the Internet it Just doesn´t Work.
Posted: Wed Jun 18, 2003 5:23 am
by releasedj
Is there anything in the $php_errormsg variable?
Posted: Wed Jun 18, 2003 5:56 am
by Luis Almeida
Nop,($php_errormsg ) it´s empty as clean air
Posted: Wed Jun 18, 2003 6:08 am
by releasedj
Can you try listing the files in the dir:
What version of PHP are you using?
Posted: Wed Jun 18, 2003 6:26 am
by cactus
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.):
Code: Select all
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
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,
Posted: Wed Jun 18, 2003 8:29 am
by Luis Almeida
Thats correct CACTUS, after adding:
Code: Select all
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
?>
I get the following error message:
Code: Select all
Warning: ftp_put(): error opening C:\TEMP\Onlyin.pps in G:\sambar60\docs\upload_last.php on line 22
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
Posted: Wed Jun 18, 2003 8:32 am
by Luis Almeida
Another thing,... thi file "ONLYIN.PPS" is only 563Kb size
My PHP is Version 4.2.3
Posted: Wed Jun 18, 2003 8:48 am
by releasedj
Have you checked that the file exists?
Posted: Wed Jun 18, 2003 8:55 am
by Luis Almeida
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 ???
Posted: Wed Jun 18, 2003 9:05 am
by releasedj
By server, I presume that you're talking about the FTP server!
What machine is the PHP script running on?