$uploadedFile = $_FILES['image']['tmp_name']; $tempFileName = CFile::secure_tmpname('tmp/', 'image_'); if (move_uploaded_file($uploadedFile, $tempFileName)) { echo 'File uploaded successfully'; } else { echo 'File could not be uploaded'; }
$userData = array('name' => 'John Doe', 'email' => 'johndoe@example.com'); $tempFileName = CFile::secure_tmpname('tmp/', 'user_data_'); if (file_put_contents($tempFileName, serialize($userData)) !== false) { echo 'User data saved successfully'; } else { echo 'User data could not be saved'; }In this example, we are using the secure_tmpname method to generate a unique file name for storing the user data. We then use the file_put_contents function to serialize the user data and store it in the temporary file. Package library: This method is part of the core PHP library and does not require any external package.