Why doesn't my FTP Upload script work on other computers?

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
<br>
Forum Commoner
Posts: 35
Joined: Thu May 01, 2008 2:42 pm

Why doesn't my FTP Upload script work on other computers?

Post by <br> »

I have a PHP FTP upload script that works perfectly on my computer, but won't work on other systems it seems... The script forwards you to a page after it runs, but on the 2 other systems I tried it on (1 Mac and 1 Vista) the script seems to be getting stopped in the middle, as you are never forwarded to the proper page and the upload doesn't execute... These 2 scripts are very similar and the same happens in both... you are taken to a blank white page (with the URL of my script). The browser says "done" in the bottom left.

Here are the scripts:

Code: Select all

<?php
$linksto = $_POST['linksto'];
$name = $_POST['name'];
$name = $_FILES['thefile']['name'];
$bass = basename($_FILES['thefile']['name']);
$filename = $_FILES['thefile']['tmp_name'];
 
$ftp_server = "(SERVER NAME)";
$ftp_user_name = "(USER NAME)";
$ftp_user_pass = "(MY PASSWORD)";
$destination_file = "/public/images/buckets";
 
$conn_id = ftp_connect($ftp_server) or die(mysql_error());
 
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass) or die(mysql_error());
ftp_pasv($conn_id, true);
ftp_chdir($conn_id,$destination_file) or die("<p>Could not change directory</p>");
 
ftp_put($conn_id, $name, $filename, FTP_BINARY) or die(mysql_error());
 
ftp_close($conn_id); // close the FTP stream
 
$url="/images/buckets/".$bass;
 
$con = mysql_connect('jankanas.db', 'JReidy', 'lalyriy') or die(mysql_error());
mysql_select_db('images') or die(mysql_error());
$sql="INSERT INTO buckets (name, url, link) VALUES ('$name', '$url', '$linksto')";
mysql_query($sql) or die(mysql_error());
mysql_close($con);
header("location:http://jreidywebdesign.com/admin/setbuckets");
?>

Code: Select all

<?php
$name = $_FILES['thefile']['name'];
$filename = $_FILES['thefile']['tmp_name'];
$bass = basename($_FILES['thefile']['name']);
 
$ftp_server = "(SERVER NAME)";
$ftp_user_name = "(USER NAME)";
$ftp_user_pass = "(MY PASSWORD)";
$destination_file = "/public/images/";
 
$conn_id = ftp_connect($ftp_server) or die(mysql_error());
 
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass) or die(mysql_error());
ftp_pasv($conn_id, true);
ftp_chdir($conn_id,$destination_file) or die("<p>Could not change directory</p>");
 
ftp_put($conn_id, $name, $filename, FTP_BINARY) or die(mysql_error());
 
ftp_close($conn_id); // close the FTP stream
 
$url='/images/'.$bass;
 
$con = mysql_connect('db', 'UserName', 'Pass') or die(mysql_error());
mysql_select_db('images') or die(mysql_error());
$sql="INSERT INTO images (filename, imageurl) VALUES ('$bass', '$url')";
mysql_query($sql) or die(mysql_error());
mysql_close($con);
header("location:http://jreidywebdesign.com/admin/upload?submitB=Y");
?>
Last edited by <br> on Sat Jul 19, 2008 3:08 pm, edited 1 time in total.
<br>
Forum Commoner
Posts: 35
Joined: Thu May 01, 2008 2:42 pm

Re: Why doesn't my FTP Upload script work on other computers?

Post by <br> »

bump
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Why doesn't my FTP Upload script work on other computers?

Post by RobertGonzalez »

You have calls to mysql_error() all over the place but you are connecting to an ftp_server. What's up with that?

Have you checked the error logs for the server to see if you are getting anything there? A blank screen is usually a fatal error of sorts which will almost always be written to the server logs.
<br>
Forum Commoner
Posts: 35
Joined: Thu May 01, 2008 2:42 pm

Re: Why doesn't my FTP Upload script work on other computers?

Post by <br> »

The error is coming at the ftp_put command... with the code below, the file is successfully uploaded without a hitch on my desktop, but I am getting "could not put" on my new laptop which runs Vista. I'm afraid I don't know how to get at the ftp error logs. My server is ProFTPD 1.3.1.

Code: Select all

<?php
$name = $_FILES['thefile']['name'];
$filename = $_FILES['thefile']['tmp_name'];
$bass = basename($_FILES['thefile']['name']);
 
$ftp_server = "server";
$ftp_user_name = "name";
$ftp_user_pass = "pass";
$destination_file = "/public/images/";
 
$conn_id = ftp_connect($ftp_server) or die("<p>Could not connect</p>");
 
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass) or die("<p>Could not log in</p>");
ftp_pasv($conn_id, true);
ftp_chdir($conn_id,$destination_file) or die("<p>Could not change directory</p>");
 
ftp_put($conn_id, $name, $filename, FTP_BINARY) or die("<p>Could not put</p>");
 
ftp_close($conn_id); // close the FTP stream
 
$url='/images/'.$bass;
 
$con = mysql_connect('server', 'name', 'pass') or die(mysql_error());
mysql_select_db('images') or die(mysql_error());
$sql="INSERT INTO images (filename, imageurl) VALUES ('$bass', '$url')";
mysql_query($sql) or die(mysql_error());
mysql_close($con);
header("location:http://jreidywebdesign.com/admin/upload?submitB=Y");
?>
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Why doesn't my FTP Upload script work on other computers?

Post by RobertGonzalez »

Does the user have permissions to put?
<br>
Forum Commoner
Posts: 35
Joined: Thu May 01, 2008 2:42 pm

Re: Why doesn't my FTP Upload script work on other computers?

Post by <br> »

Added ftp_chmod()'s... still says only "could not put"

Code: Select all

<?php
$name = $_FILES['thefile']['name'];
$filename = $_FILES['thefile']['tmp_name'];
$bass = basename($_FILES['thefile']['name']);
 
$ftp_server = "ftp.phx.nearlyfreespeech.net";
$ftp_user_name = "JReidy_webdesign";
$ftp_user_pass = "lalyriy";
$destination_file = "/public/images/";
 
$conn_id = ftp_connect($ftp_server) or die("<p>Could not connect</p>");
 
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass) or die("<p>Could not log in</p>");
ftp_pasv($conn_id, true);
ftp_chdir($conn_id,$destination_file) or die("<p>Could not change directory</p>");
ftp_chmod($conn_id, "0777", $destination_file) or die("<p>Could not chmod1</p>");
ftp_put($conn_id, $name, $filename, FTP_BINARY) or die("<p>Could not put</p>");
ftp_chmod($conn_id, "0755", $destination_file) or die("<p>Could not chmod2</p>");
ftp_close($conn_id); // close the FTP stream
 
$url='/images/'.$bass;
 
$con = mysql_connect('jankanas.db', 'JReidy', 'lalyriy') or die(mysql_error());
mysql_select_db('images') or die(mysql_error());
$sql="INSERT INTO images (filename, imageurl) VALUES ('$bass', '$url')";
mysql_query($sql) or die(mysql_error());
mysql_close($con);
header("location:http://jreidywebdesign.com/admin/upload?submitB=Y");
?>
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Why doesn't my FTP Upload script work on other computers?

Post by s.dot »

I have had problems with permissions and using ftp_chmod() on windows machines. Is the target server running a windows OS?

Also, $destination_file starts with / .. are you sure it's not a relative path and should be 'public/bucket' ?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
<br>
Forum Commoner
Posts: 35
Joined: Thu May 01, 2008 2:42 pm

Re: Why doesn't my FTP Upload script work on other computers?

Post by <br> »

It seems that my ftp_chmod()'s are working now that I took the quotes off of 0777... with the quotes around it my permissions were being changed to 411 for some reason.

When I took the slash away from "/public/images" i got:

Code: Select all

Warning: ftp_chdir() [function.ftp-chdir]: public/images/: No such file or directory in /f1/content/webdesign/public/admin/upload/fileupload2.php on line 15
Since it works on at least 2 machines with the "/" I'm going to assume that it's correct as is...

I am still getting an ftp_put() error or my laptop, though. I was able to upload on a friend's computer a couple days ago... I fail to see what factor could be causing an error only on certain machines. I must be overlooking something... but WHAT?!?! :banghead:

Here's the current code:

Code: Select all

<?php
$name = $_FILES['thefile']['name'];
$filename = $_FILES['thefile']['tmp_name'];
$bass = basename($_FILES['thefile']['name']);
 
$ftp_server = "server";
$ftp_user_name = "user";
$ftp_user_pass = "pass";
$destination_file = "/public/images/";
 
$conn_id = ftp_connect($ftp_server) or die("<p>Could not connect</p>");
 
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass) or die("<p>Could not log in</p>");
ftp_pasv($conn_id, true);
ftp_chdir($conn_id,$destination_file) or die("<p>Could not change directory</p>");
ftp_chmod($conn_id, 0777, $destination_file) or die("<p>Could not chmod1</p>");
ftp_put($conn_id, $name, $filename, FTP_BINARY) or die("<p>Could not put</p>");
ftp_chmod($conn_id, 0777, $destination_file) or die("<p>Could not chmod2</p>");
ftp_close($conn_id); // close the FTP stream
 
$url='/images/'.$bass;
 
$con = mysql_connect('db', 'user', 'pass') or die(mysql_error());
mysql_select_db('images') or die(mysql_error());
$sql="INSERT INTO images (filename, imageurl) VALUES ('$bass', '$url')";
mysql_query($sql) or die(mysql_error());
mysql_close($con);
header("location:http://jreidywebdesign.com/admin/upload?submitB=Y");
?>
Post Reply