upload images via ftp using php

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
thx967
Forum Newbie
Posts: 20
Joined: Thu Feb 24, 2005 3:14 pm

upload images via ftp using php

Post by thx967 »

I've built a form that will upload images to a directory which seems to be working - no validation though.

However - I still have one hurdle.

I'm trying to upload the file to one of my other websites on a completely different server thats not setup for php - rather asp. I have ftp access - just can't figure out how to make the connection via php script so the upload goes there.

Any ideas??
thx967
Forum Newbie
Posts: 20
Joined: Thu Feb 24, 2005 3:14 pm

Post by thx967 »

Well I managed to make the ftp conection - now my form upload doesn't work - lol

I must be missing an end satement somewhere betwen the functions or something.

Any suggestions?

Heres what I have so far

Code: Select all

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>file upload</title>
</head>
<?php
$ftp_server = "ftp.anysite.com";
$ftp_user = "user";
$ftp_pass = "pass";

// set up a connection or die
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");

// try to login
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
  echo "Connected as $ftp_user@$ftp_server\n";
} else {
  echo "Couldn't connect as $ftp_user\n";
}

// close the connection
ftp_close($conn_id);  

?>
<body>
<?php
$path = 'ftp.anysite.com/UPLOAD_TEST';


if(isset($_FILES['file']) && is_uploaded_file($_FILES['file']['tmp_name']))
{
$filename = $_FILES['file']['tmp_name'];
$destination = $path . $_FILES['file']['name'];
if (file_exists($destination))
{ echo 'File already exists!<br />'; }
else
if(move_uploaded_file($filename,$destination))
{ echo 'File uploaded!<br />'; }
else
{ echo ' ** Failure! ** <br />'; }
}

?>
<form method="post" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" value="Upload Image" action="file_upload.php">
</form>
</body>
JCART | Please use

Code: Select all

tags when posting php code. Review [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
asmie
Forum Newbie
Posts: 11
Joined: Mon Jun 20, 2005 8:45 am

Post by asmie »

Hie,
The file isnt getting uploaded bcoz you dont have the permission to upload to that directory.

Try changing the permission to the directory.

Code: Select all

chmod("/somedir/somefile", 0777);
and then do the uploading.

Hope this helps !
:)
Asmie
thx967
Forum Newbie
Posts: 20
Joined: Thu Feb 24, 2005 3:14 pm

Post by thx967 »

I've checked the directory permissions - its already 777
Post Reply