Hi
I'm new to using PHP upload functions and need some help with an error that this extract of code is producing. The variable $_POST['photo1_upload'] contains the data given by a FILE input object on the previous page, from which this variable is posted. The variable contains a filename/path local to my computer, and I am attempting to upload this file to my remote FTP server on which my site is stored, under the filename 'target.bin'.
IE reports that parameter 3 in ftp_put is an invalid FTP resource.
Can anyone interpret this problem? Secondly, does the following code do what I want it to do?
if(!$success = ftp_put($conn, 'target.bin', $_POST['photo1_upload'], FTP_BINARY))
{
echo 'Error: Could not upload file to server';
ftp_quit($conn);
exit();
}
Thanks very much
Markwell if you use <input type="file"> then the file is pass to the server on submition of the form...
the ftp function of php is only a ftp client so the source file *need* to be on the same machine as the php server!
check out <!-- m --><a class="postlink" href="http://ca3.php.net/features.file-uploadalso">http://ca3.php.net/features.file-uploadalso</a><!-- m -->, you access it through the $_FILE variable, not $_POSTOkay - this is the situation clearly in words.
I have a file, MyFile.doc on the D:\ drive of my computer.
I have my site, hosted on a remote server. Every time I write a PHP script, because I don't have PHP installed on my computer, I upload my scripts to my server and run them from the server.
I simply want to copy MyFile.doc, stored on the D:\ drive of my computer, to the remote server on which my site is stored, using PHP code executed on the remote server.
Please explain how this is done, using FTP functions or otherwise. Your help would be very much appreciated.
Sincerely
Markthis is a script a user posted relating to the ftp_put function
Friends,
If you wanna upload files from your harddisk by a form to a specified ftp this sample can help you...
First of all create the form:
<html>
<body marginwidth=4 marginheight=4 topmargin=4 leftmargin=4 bgcolor=white vlink="#0000ff" link="#0000ff">
<form name="Attachments" method=POST action="sendimage.php" enctype="multipart/form-data">
<input type=hidden name=box value="">
<tr>
<td nowrap width="1%"> <b>Image:</b></td>
<td colspan=2>
<input type=file name=source_file size=20> <br>
</td>
</tr>
<input type=submit name=btnSubmit value=Submit size=20 style="border: 1px solid #0000FF"></form>
</body>
</html>
The critical point in this form is the usage of enctype="multipart/form-data"
If you don't use this part your upload operations won't work.
Then u must create sendimage.php as follows:
<?php $ftp_server='190.148.20.201';//serverip
$conn_id = ftp_connect($ftp_server);
// login with username and password
$user="username";
$passwd="*****";
$login_result = ftp_login($conn_id, $user, $passwd);
// check connection
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
die;
} else {
echo "<br>Connected to $ftp_server, for user $user<br>";
}
//directorylike /www.velibaba.com/images
ftp_chdir($conn_id, "www.velibab.com");
ftp_chdir($conn_id, "compimages");
//$destination_file=ftp_pwd($conn_id);
$destination_file="x.jpg";
echo ("<br>");
print $destination_file;
echo ("<br>");
// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
// check upload status
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
}
// close the FTP stream
ftp_close($conn_id);
?>
In this example code $source_file is the path of the file in your disk, and destination file is the name of the uploaded file in ftpserver.
In this code I use ftp_chdir to give the path of the
uploaded file within ftpserver..
For your questions about all categories of PHP my email:[email protected]
c u...that just a way to upload with more security/options or when you cannot chmod a folder than the standart form upload...
check out the file upload on the php.net (my post earlier)
you don't need the ftp function!
I'm new to using PHP upload functions and need some help with an error that this extract of code is producing. The variable $_POST['photo1_upload'] contains the data given by a FILE input object on the previous page, from which this variable is posted. The variable contains a filename/path local to my computer, and I am attempting to upload this file to my remote FTP server on which my site is stored, under the filename 'target.bin'.
IE reports that parameter 3 in ftp_put is an invalid FTP resource.
Can anyone interpret this problem? Secondly, does the following code do what I want it to do?
if(!$success = ftp_put($conn, 'target.bin', $_POST['photo1_upload'], FTP_BINARY))
{
echo 'Error: Could not upload file to server';
ftp_quit($conn);
exit();
}
Thanks very much
Markwell if you use <input type="file"> then the file is pass to the server on submition of the form...
the ftp function of php is only a ftp client so the source file *need* to be on the same machine as the php server!
check out <!-- m --><a class="postlink" href="http://ca3.php.net/features.file-uploadalso">http://ca3.php.net/features.file-uploadalso</a><!-- m -->, you access it through the $_FILE variable, not $_POSTOkay - this is the situation clearly in words.
I have a file, MyFile.doc on the D:\ drive of my computer.
I have my site, hosted on a remote server. Every time I write a PHP script, because I don't have PHP installed on my computer, I upload my scripts to my server and run them from the server.
I simply want to copy MyFile.doc, stored on the D:\ drive of my computer, to the remote server on which my site is stored, using PHP code executed on the remote server.
Please explain how this is done, using FTP functions or otherwise. Your help would be very much appreciated.
Sincerely
Markthis is a script a user posted relating to the ftp_put function
Friends,
If you wanna upload files from your harddisk by a form to a specified ftp this sample can help you...
First of all create the form:
<html>
<body marginwidth=4 marginheight=4 topmargin=4 leftmargin=4 bgcolor=white vlink="#0000ff" link="#0000ff">
<form name="Attachments" method=POST action="sendimage.php" enctype="multipart/form-data">
<input type=hidden name=box value="">
<tr>
<td nowrap width="1%"> <b>Image:</b></td>
<td colspan=2>
<input type=file name=source_file size=20> <br>
</td>
</tr>
<input type=submit name=btnSubmit value=Submit size=20 style="border: 1px solid #0000FF"></form>
</body>
</html>
The critical point in this form is the usage of enctype="multipart/form-data"
If you don't use this part your upload operations won't work.
Then u must create sendimage.php as follows:
<?php $ftp_server='190.148.20.201';//serverip
$conn_id = ftp_connect($ftp_server);
// login with username and password
$user="username";
$passwd="*****";
$login_result = ftp_login($conn_id, $user, $passwd);
// check connection
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
die;
} else {
echo "<br>Connected to $ftp_server, for user $user<br>";
}
//directorylike /www.velibaba.com/images
ftp_chdir($conn_id, "www.velibab.com");
ftp_chdir($conn_id, "compimages");
//$destination_file=ftp_pwd($conn_id);
$destination_file="x.jpg";
echo ("<br>");
print $destination_file;
echo ("<br>");
// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
// check upload status
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
}
// close the FTP stream
ftp_close($conn_id);
?>
In this example code $source_file is the path of the file in your disk, and destination file is the name of the uploaded file in ftpserver.
In this code I use ftp_chdir to give the path of the
uploaded file within ftpserver..
For your questions about all categories of PHP my email:[email protected]
c u...that just a way to upload with more security/options or when you cannot chmod a folder than the standart form upload...
check out the file upload on the php.net (my post earlier)
you don't need the ftp function!