Helpful Information
 
 
Category: FTP Help
FTP Upload

I've been pouring over the following code all day, but can't seem to get it work. I appreciate anyone that can point out any errors.




$imageUpFile = $_FILES['file']['tmp_name'];
$imageType = $_FILES['file']['type'];
$imageName = $_FILES['file']['name'];

echo" $imageUpFile, $imageType, $imageName";


//Open the uploaded pic (temp file)
if ($thePic = fopen ($imageUpFile, "rb"))
{
//read temp file into var
$savePic = fread($thePic, filesize($imageUpFile));

//Open a new file in the correct directory using the name of the uploaded pic file
if ($fileHandle = fopen("ftp://username:apassword@somehost.com/htdocs/www/uploads/$imageName","w"))
{
//Put data into just opened file pointer
if (fwrite ($fileHandle, $savePic))
{
echo "file <b>$imageName</b> successfully written";
}
else
{
echo "file <b>$imageName</b> was NOT written";
}
}
fclose ($fileHandle);
fclose ($thePic);
}
else
{
// The file was not created. Inform the user.
echo "<b> The file: $imageUpFile could not be created!</b>";
}

use instead the ftp functions.

Is there anything wrong with you using the copy() (http://www.php.net/copy) or move_uploaded_file() (http://www.php.net/move_uploaded_file) functions? It makes more sense to me to use this in your instance.










privacy (GDPR)