I agree with djr33...
I think the point of the ftp functions is to get to a third party server.. Let's say for instance you want to upload a file to your web page, but you're really storing on another server (that has ftp access)...
Printable View
I agree with djr33...
I think the point of the ftp functions is to get to a third party server.. Let's say for instance you want to upload a file to your web page, but you're really storing on another server (that has ftp access)...
How do you figure out 'tmp_name'?
Ok, I'm getting an error with this code - undefined index?
I think it's basically saying it can't find where the temp file's been uploaded. How do we find this out?PHP Code:$file = $_REQUEST['file'];
$basedir = 'd:\webspace\ADMIN\alexjewell.com\WWW\amanda';
$tmp_name = $_FILES[$file]['tmp_name'];
$new_name = $_FILES[$file]['name'];
move_uploaded_file($tmp_name , $basedir.$new_name);
echo "<p>File uploaded successfully</p>";
ps - should I be using something along the lines of is_uploaded_file or $HTTP_POST_FILES?
Ok, I've worked around some code and done some things. The PHP errors are gone, but now my second die statement is showing up: "Couldn't upload file".
I decided to echo the address of the new file, and it's really weird:
I practiced with a file called hovers.js...this is what it echoed: d:\webspace\ADMIN\alexjewell.com\WWW\amanda\h
It took the first letter and dropped the rest? I then used a file called js.php, and it ended up just like the h: amanda\j.
What's going on?!PHP Code:$file = $_REQUEST['file'] or die("<p>Could not retrieve file</p>");
$basedir = 'd:\webspace\ADMIN\alexjewell.com\WWW\amanda\\';
$tmp_name = $file['tmp_name'];
$new_name = $file['name'];
echo "<p>".$basedir.$new_name."</p>";
move_uploaded_file($tmp_name , $basedir.$new_name) or die("<p>Couldn't upload file</p>");
echo "<p>File uploaded successfully</p>";
Ok, the problem has been solved. I went with a different avenue altogether. But if anyone would like to point out the problems with the above script, that'd be cool.
First you can find out that it uses ASCII or binary.
Then put it.
<?php
// --------------------------------------------------------------------
// THE TRIGGER
// --------------------------------------------------------------------
// set the various variables
$ftproot = "/public_html/test/";
$srcroot = "/home/kristy/scripts/";
$srcrela = "iwm/";
// connect to the destination FTP & enter appropriate directories both locally and remotely
$ftpc = ftp_connect("ftp.mydomain.com");
$ftpr = ftp_login($ftpc,"username","password");
if ((!$ftpc) || (!$ftpr)) { echo "FTP connection not established!"; die(); }
if (!chdir($srcroot)) { echo "Could not enter local source root directory."; die(); }
if (!ftp_chdir($ftpc,$ftproot)) { echo "Could not enter FTP root directory."; die(); }
// start ftp'ing over the directory recursively
ftpRec ($srcrela);
// close the FTP connection
ftp_close($ftpc);
// --------------------------------------------------------------------
// THE ACTUAL FUNCTION
// --------------------------------------------------------------------
function ftpRec ($srcrela)
{
global $srcroot;
global $ftproot;
global $ftpc;
global $ftpr;
// enter the local directory to be recursed through
chdir($srcroot.$srcrela);
// check if the directory exists & change to it on the destination
if (!ftp_chdir($ftpc,$ftproot.$srcrela))
{
// remote directory doesn't exist so create & enter it
ftp_mkdir ($ftpc,$ftproot.$srcrela);
ftp_chdir ($ftpc,$ftproot.$srcrela);
}
if ($handle = opendir("."))
{
while (false !== ($fil = readdir($handle)))
{
if ($fil != "." && $fil != "..")
{
// check if it's a file or directory
if (!is_dir($fil))
{
// it's a file so upload it
ftp_put($ftpc, $ftproot.$srcrela.$fil, $fil, FTP_BINARY);
}
else
{
// it's a directory so recurse through it
if ($fil == "templates")
{
// I want the script to ignore any directories named "templates"
// and therefore, not recurse through them and upload their contents
}
else
{
ftpRec ($srcrela.$fil."/");
chdir ("../");
}
}
}
}
closedir($handle);
}
}
?>