FTP Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsSystem AdministrationFTP Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 9th, 2002, 04:02 PM
Mobius Man's Avatar
Mobius Man Mobius Man is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 98 Mobius Man User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 39 m 15 sec
Reputation Power: 7
FTP upload script errors

I've been working on making a script to upload image files to the server through a PHP script. I have 2 files: images.html (which is the upload form), and image_manager.php (which uploads the image file thru FTP). I've been going through the code for an hour, and still can't figure out my errors. It has something to do with my $connect variable.

Here's the errors I'm getting:

Warning: ftp_login() expects parameter 1 to be resource, string given in /usr/home/hostultra/hostultra.com/html/hosted/sites/Mobius_Man/image_manager.php on line 18

Warning: ftp_mkdir() expects parameter 1 to be resource, string given in /usr/home/hostultra/hostultra.com/html/hosted/sites/Mobius_Man/image_manager.php on line 24

Warning: ftp_chdir() expects parameter 1 to be resource, string given in /usr/home/hostultra/hostultra.com/html/hosted/sites/Mobius_Man/image_manager.php on line 25
uploaded!
Warning: ftp_close() expects parameter 1 to be resource, string given in /usr/home/hostultra/hostultra.com/html/hosted/sites/Mobius_Man/image_manager.php on line 50


And here's my script:
PHP Code:
<?php

/***********************************************
                    Image FTP Uploading Script            
                            (image_manager.php)        
***********************************************/


//enter your FTP server's name, as well as your username and password into these variables
$ftp_server="ftp.hostultra.com";
$ftp_user="Mobius_Man";
$ftp_pass="********";

//variable that connects to the FTP server
$connect="ftp_connect(ftp.hostultra.com, 21, 120)";

//logins into FTP server account
ftp_login($connect$ftp_user$ftp_pass);

//checks for image directory
if (! @ftp_chdir($ftp_server"/news/images"))
{
    
//if directory doesn't exist, it is now created
    
ftp_mkdir($ftp_server"/news/images");
    
ftp_chdir($ftp_server"/news/images");    
}

else
{
//else statement
}

//destination file variable
$des_file="ftp_pwd($connect)";

$upload="ftp_put($connect, $des_file, $source_file, FTP_BINARY)";

//checks to see if the file was successfully uploaded
if    (!$upload)
{
    echo 
"Upload of $source_file was unsuccessful!";
}

else
{
    echo 
"$source_file uploaded!";
}

//closes FTP server connection
ftp_close($connect);

?>

Reply With Quote
  #2  
Old October 9th, 2002, 04:31 PM
Tzicha's Avatar
Tzicha Tzicha is offline
Here, not there
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 312 Tzicha User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 36 sec
Reputation Power: 7
Read: http://www.php.net/manual/en/ref.ftp.php

You need to send a connection id(or connection resource) to the ftp functions.

Reply With Quote
  #3  
Old October 9th, 2002, 05:01 PM
hedge hedge is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2002
Posts: 693 hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 23 h 47 m 32 sec
Reputation Power: 20
Why are you putting the function call in quotes.

ie.
//variable that connects to the FTP server
$connect="ftp_connect(ftp.hostultra.com, 21, 120)";


s/b $connect = ftp_connect('ftp.hostultra.com',21,120);

... all the way down

Reply With Quote
  #4  
Old October 9th, 2002, 09:10 PM
Mobius Man's Avatar
Mobius Man Mobius Man is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 98 Mobius Man User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 39 m 15 sec
Reputation Power: 7
Well, I changed that stuff, however it still isn't working. But, now I only get these errors:

Warning: ftp_mkdir() expects parameter 1 to be resource, string given in /usr/home/hostultra/hostultra.com/html/hosted/sites/Mobius_Man/image_manager.php on line 24

Warning: ftp_chdir() expects parameter 1 to be resource, string given in /usr/home/hostultra/hostultra.com/html/hosted/sites/Mobius_Man/image_manager.php on line 25

Warning: ftp_put(): error opening in /usr/home/hostultra/hostultra.com/html/hosted/sites/Mobius_Man/image_manager.php on line 36
Upload of was unsuccessful!

Here's the form code:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
	<title>Image Upload</title>
</head>
<script language="JavaScript">

		function insertImage(imgPath)
		{
			parent.opener.iView.focus();
			parent.window.close();
			parent.opener.iView.document.execCommand('insertimage', false, imgPath);
		}

	</script>
<body>
<form action="image_manager.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="doUpload" value="true">
		<div class="text">Upload File:</div>
		<input type="file" name="source_file"> <input type="submit" value="Upload" onClick="this.value='Please Wait...'">
	
</form>


</body>
</html>


PHP Code:
<?php

/***********************************************
                    Image FTP Uploading Script            
                            (image_manager.php)        
***********************************************/


//enter your FTP server's name, as well as your username and password into these variables
$ftp_server="ftp.hostultra.com";
$ftp_user="Mobius_Man";
$ftp_pass="TummyKitte";

//variable that connects to the FTP server
$connect ftp_connect('ftp.hostultra.com',21,120);

//logins into FTP server account
ftp_login($connect$ftp_user$ftp_pass);

//checks for image directory
if (! @ftp_chdir($ftp_server"/news/images"))
{
    
//if directory doesn't exist, it is now created
    
ftp_mkdir('$ftp_server'"/news/images");
    
ftp_chdir('$ftp_server'"/news/images");    
}

else
{
//else statement
}

//destination file variable
$des_file ftp_pwd($connect);

$upload ftp_put($connect$des_file$source_fileFTP_BINARY);

//checks to see if the file was successfully uploaded
if    (!$upload)
{
    echo 
"Upload of $source_file was unsuccessful!";
}

else
{
    echo 
"$source_file uploaded!";
}

//closes FTP server connection
ftp_close($connect);

?>



Oh the joys of trying to learn PHP...

Reply With Quote
  #5  
Old October 10th, 2002, 11:42 AM
hedge hedge is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2002
Posts: 693 hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 23 h 47 m 32 sec
Reputation Power: 20
Quote:
Originally posted by Mobius Man
Well, I changed that stuff, however it still isn't working. But, now I only get these errors:

Warning: ftp_mkdir() expects parameter 1 to be resource, string given in /usr/home/hostultra/hostultra.com/html/hosted/sites/Mobius_Man/image_manager.php on line 24

Warning: ftp_chdir() expects parameter 1 to be resource, string given in /usr/home/hostultra/hostultra.com/html/hosted/sites/Mobius_Man/image_manager.php on line 25

Warning: ftp_put(): error opening in /usr/home/hostultra/hostultra.com/html/hosted/sites/Mobius_Man/image_manager.php on line 36
Upload of was unsuccessful!

Here's the form code:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
	<title>Image Upload</title>
</head>
<script language="JavaScript">

		function insertImage(imgPath)
		{
			parent.opener.iView.focus();
			parent.window.close();
			parent.opener.iView.document.execCommand('insertimage', false, imgPath);
		}

	</script>
<body>
<form action="image_manager.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="doUpload" value="true">
		<div class="text">Upload File:</div>
		<input type="file" name="source_file"> <input type="submit" value="Upload" onClick="this.value='Please Wait...'">
	
</form>


</body>
</html>


PHP Code:
<?php

/***********************************************
                    Image FTP Uploading Script            
                            (image_manager.php)        
***********************************************/


//enter your FTP server's name, as well as your username and password into these variables
$ftp_server="ftp.hostultra.com";
$ftp_user="Mobius_Man";
$ftp_pass="TummyKitte";

//variable that connects to the FTP server
$connect ftp_connect('ftp.hostultra.com',21,120);

//logins into FTP server account
ftp_login($connect$ftp_user$ftp_pass);

//checks for image directory
if (! @ftp_chdir($ftp_server"/news/images"))
{
    
//if directory doesn't exist, it is now created
    
ftp_mkdir('$ftp_server'"/news/images");
    
ftp_chdir('$ftp_server'"/news/images");    
}

else
{
//else statement
}

//destination file variable
$des_file ftp_pwd($connect);

$upload ftp_put($connect$des_file$source_fileFTP_BINARY);

//checks to see if the file was successfully uploaded
if    (!$upload)
{
    echo 
"Upload of $source_file was unsuccessful!";
}

else
{
    echo 
"$source_file uploaded!";
}

//closes FTP server connection
ftp_close($connect);

?>



Oh the joys of trying to learn PHP...


Well it's the same problem.. when you put variables in quotes they have became literals, so instead of passing your connectionid you are passing a string '$connectionid' to the function... which it hates.

Reply With Quote
  #6  
Old July 15th, 2003, 12:01 PM
alexcd alexcd is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: PANAMA
Posts: 1 alexcd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I am getting upload one image in php and check if upload is successful, however, when the script finish for close the connection ftp, I receive this error: Fatal error: Call to undefined function: ftp_close() in c:\apache\htdocs\test.php on line 11

I am using ftp_close($conn_id); for close the $conn_id connection. Can you tell me what is happening?

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationFTP Help > FTP upload script errors


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT