I'm trying to upload a file to an FTP server. It gets caught in the if statement which states that the directory must be chmode 777 however I have manually chmode 77 every directory in the ftp as well as adding a function in the code.
Secondly, I'd like to ask about the .tmp files that are created once an upload process has begun. Are they uploaded to the FTP? If so, do I need to also allow access for .tmp files along with .mp3 files? I'm pretty unaware of what their use in the process actually is so if anyone could take the time to explain it that'd be very helpful.
some variable contents:
$upload_path = /htdocs/site2/telemessages/en/Apologies
$_FILES['userfile']['tmp_name'] = /tmp/phpwkfxrW
Here is the code I'm using to pass the file to the FTP:
$ftp_server="***********";
$ftp_user_name="************";
$ftp_user_pass="***********";
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
if(ftp_login($conn_id, $ftp_user_name, $ftp_user_pass)){
// Configuration - Your Options
$allowed_filetypes = array('.mp3','.tmp'); // These will be the types of file that will pass the validation.
$max_filesize = 2097152; // Maximum filesize in BYTES (currently 2MB).
$cutName = substr($_SESSION['dir'], 0, -1);
$upload_path = "htdocs/site/telemessages/en/". $_SESSION['dir'];
echo "upload path: ".$upload_path; // The place the files will be uploaded to (currently a 'files' directory).
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.
// Check if the filetype is allowed, if not DIE and inform the user.
if(!in_array($ext,$allowed_filetypes))
die('The file you attempted to upload is not allowed.');
// Now check the filesize, if it is too large then DIE and inform the user.
if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
die('The file you attempted to upload is too large.');
// Check if we can upload to the specified path, if not DIE and inform the user.
if(!is_writable($upload_path))
die('You cannot upload to the specified directory, please CHMOD it to 777.');
// We'll start handling the upload in the next step
echo"FORCE: ".$_FILES['userfile']['tmp_name'];
//Upload the file to your specified path.
$result = move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename);
if(!$result)
{
return -1;
}
else
{
echo $result;
//SET PROPER READ PERMISSIONS
$result2 = chmod($upload_path, 0777);
echo "Result: ".$result2;
}
}else{
echo "login failed";
}
Thanks for any help in advance.